Skip to content

time conversion from second to Y M D H M S format

7 messages · Uwe Ligges, uday, R. Michael Weylandt +2 more

#
I have some time data and which is in seconds 

time <-c( 126230400 126252000 126273600 126295200 126316800 126338400)
now I wanted to convert this time to Y M D H M S format

I have tried following codes but it does not give me the  out put in  Y M D
H M S

time_t1 <- as.POSIXlt(time, origin="2005-01-01", tz="GMT") 
& 
time_f <- as.POSIXct(time, origin="2005-01-01", tz="GMT")

So somebody could please tell me how to fix this problem. 

Thanks  

	



--
View this message in context: http://r.789695.n4.nabble.com/time-conversion-from-second-to-Y-M-D-H-M-S-format-tp4350831p4350831.html
Sent from the R help mailing list archive at Nabble.com.
#
On 02.02.2012 09:26, uday wrote:
format(time_t1, "%Y %m %d %H %M %S")

Uwe Ligges
#
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.





--
View this message in context: http://r.789695.n4.nabble.com/time-conversion-from-second-to-Y-M-D-H-M-S-format-tp4350831p4352062.html
Sent from the R help mailing list archive at Nabble.com.
#
It works for me as well so there's something funny on your end: please
run the following *verbatim* (in a vanilla R session):

sink("ForRHelp.txt")
print(sessionInfo())
cat("\n")
print(.Platform)
time <-as.POSIXct(c( 126230400, 126252000, 126273600),
origin="2005-01-01", tz="GMT")
print(time)
cat(format(time[1], "%Y %m %d %H %M %S"), "\n")
cat(format(time[2], "%Y %m %d %H %M %S"), "\n")
cat(format(time[3], "%Y %m %d %H %M %S"), "\n")
sink()
print(paste("Text file in", getwd()))

and send the resulting txt file to the list (so we can see exactly
your system config and what not).

Michael
On Thu, Feb 2, 2012 at 11:57 AM, uday <uday_143_4u at hotmail.com> wrote:
#
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
[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"
[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
#
On 02-02-2012, at 19:23, R. Michael Weylandt wrote:

            
I appear to have the same or similar problem on Mac OS X 10.6.8
I ran the above script with R --vanilla.
The result is

R version 2.14.1 Patched (2012-01-30 r58238)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_GB/en_GB/en_GB/C/en_GB/en_GB

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

$OS.type
[1] "unix"

$file.sep
[1] "/"

$dynlib.ext
[1] ".so"

$GUI
[1] "X11"

$endian
[1] "little"

$pkgType
[1] "mac.binary.leopard"

$path.sep
[1] ":"

$r_arch
[1] "x86_64"

[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 00 00 00 
2009 01 01 06 00 00 
2009 01 01 12 00 00 


Berend
#
On 02-02-2012, at 21:10, Berend Hasselman wrote:

            
Disregard my previous posting.
Results are correct.

Berend