[R] convert 12 time stamp to 24 hour

PIKAL Petr petr.pikal at precheza.cz
Fri Feb 8 14:35:49 CET 2013


Hi

Does not work in some locale environment

> strptime(testtime, "%Y-%m-%d %I:%M:%S %p") 
[1] NA

> Sys.getlocale("LC_TIME")
[1] "Czech_Czech Republic.1250"

> Sys.setlocale("LC_TIME", "C")
[1] "C"

> strptime(testtime, "%Y-%m-%d %I:%M:%S %p") 
[1] "2013-01-01 13:00:01"

Regards
Petr

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Pascal Oettli
> Sent: Friday, February 08, 2013 11:08 AM
> To: e-letter
> Cc: r-help at r-project.org
> Subject: Re: [R] convert 12 time stamp to 24 hour
> 
> Hello,
> 
> Try this:
> 
>  > testtime<-("2013-01-01 01:00:01 PM")
>  > strptime(testtime, "%Y-%m-%d %I:%M:%S %p") [1] "2013-01-01 13:00:01"
> 
> HTH,
> Pascal
> 
> 
> Le 08/02/2013 18:44, e-letter a écrit :
> > Readers,
> >
> > For a 12 hour time stamp:
> >
> >> testtime<-("2013-01-01 01:00:01 PM")
> >> testtime
> > [1] "2013-01-01 01:00:01 PM"
> >> testtime24hour<-strftime(testtime,'%H:%M:%S')
> >> testtime24hour
> > [1] "01:00:01"
> >
> > how to convert to 24 hour format so that the object 'testtime24hour'
> is:
> >
> > '13:00:01'
> >
> > Thanks.
> >
> > --
> > r2151
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > 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.
> >
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.



More information about the R-help mailing list