Skip to content
Back to formatted view

Raw Message

Message-ID: <F7E6D18CC2877149AB5296CE54EA2766035C8E@WAXMXOLYMB001.WAX.wa.lcl>
Date: 2012-02-02T19:43:41Z
From: Nordlund, Dan (DSHS/RDA)
Subject: time conversion from second to Y M D H M S format
In-Reply-To: <1328201846098-4352062.post@n4.nabble.com>

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of uday
> Sent: Thursday, February 02, 2012 8:57 AM
> To: r-help at r-project.org
> Subject: Re: [R] time conversion from second to Y M D H M S format
> 
> Dear Uwe ,
> Thanks for reply
> I have tried format function that u suggested (format(time_t1, "%Y %m
> %d %H
> %M %S")  and I got
> format(time_t1, "%Y %m %d %H %M %S")
> [1] "126230400" "126252000" "126273600" "126295200" "126316800"
> "126338400"
> 
> 
> I think something  is not working correct.
> 
> 

You are right something is not working correctly.  But you haven't shown what you did from beginning to end, so we don't know what that something might be.  Try this

> time <-c( 126230400, 126252000, 126273600, 126295200, 126316800, 126338400)
> time_t1<- as.POSIXlt(time, origin="2005-01-01", tz="GMT")
> time_t1
[1] "2009-01-01 00:00:00 GMT" "2009-01-01 06:00:00 GMT"
[3] "2009-01-01 12:00:00 GMT" "2009-01-01 18:00:00 GMT"
[5] "2009-01-02 00:00:00 GMT" "2009-01-02 06:00:00 GMT"
> format(time_t1, "%Y %m %d %H %M %S")
[1] "2009 01 01 00 00 00" "2009 01 01 06 00 00" "2009 01 01 12 00 00"
[4] "2009 01 01 18 00 00" "2009 01 02 00 00 00" "2009 01 02 06 00 00"
>

Does that not do what you wanted?

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204