POSIXct format

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

POSIXct format

Bogaso
Hi,

I am trying to format my Character strings to POSIXct as below :

> as.POSIXct('2018-11-2700:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
[1] "2018-11-27 UTC"
> as.POSIXct('2018-11-2701:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
[1] "2018-11-27 01:00:00 UTC"

For the first case, I wanted to see "2018-11-27 00:00:00 UTC", but the
Hour/Min/Sec part was missing in R output. Is it possible to get consistent
formatting in both cases?

Thanks for your help. Regards

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: POSIXct format

Ben Tupper-2
Hi,

It is because the print method for POSIXct likely tries to simplify.  To see it in the format you desire, you need to be explicit when calling it.

x = as.POSIXct('2018-11-2700:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
format(x, "%Y-%m-%d %H:%M:%S %Z")
[1] "2018-11-27 00:00:00 UTC"

Cheers,
Ben

> On Dec 4, 2018, at 7:51 AM, Christofer Bogaso <[hidden email]> wrote:
>
> Hi,
>
> I am trying to format my Character strings to POSIXct as below :
>
>> as.POSIXct('2018-11-2700:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
> [1] "2018-11-27 UTC"
>> as.POSIXct('2018-11-2701:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
> [1] "2018-11-27 01:00:00 UTC"
>
> For the first case, I wanted to see "2018-11-27 00:00:00 UTC", but the
> Hour/Min/Sec part was missing in R output. Is it possible to get consistent
> formatting in both cases?
>
> Thanks for your help. Regards
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.