Jim Hargreaves
2010-Jul-20 13:26 UTC
[R] Convert Unix (Epoch) timestamp to DD/MM/YY and HH:MM:SS
Dear List, After much searching with no success, I would like to ask how I can convert a unix/POSIX time (seconds since Jan 01, 1970) into a string like "01/01/1970 00:00" This is probably easily done with a system(date...) but it would be great if I could do it in R. Kind Regards, Jim Hargreaves
David Winsemius
2010-Jul-20 13:42 UTC
[R] Convert Unix (Epoch) timestamp to DD/MM/YY and HH:MM:SS
On Jul 20, 2010, at 9:26 AM, Jim Hargreaves wrote:> Dear List, > > After much searching with no success, I would like to ask how I can > convert a unix/POSIX time (seconds since Jan 01, 1970) into a string > like "01/01/1970 00:00" > > This is probably easily done with a system(date...) but it would be > great if I could do it in R.By default DateTime objects are printed similarly to your specification: > Sys.time() [1] "2010-07-20 09:34:36 EDT" > as.numeric( Sys.time() ) # the internal representation [1] 1279632906 The default format for the default print function is YYYY-MM-DD HH:MM TZ. You can find the format codes with: ?strptime > print(Sys.time(), format="%m/%d/%Y %H:%M") # your request is ambiguous w.r.t month and day order [1] "07/20/2010 09:39 EDT">-- David Winsemius, MD West Hartford, CT
jim holtman
2010-Jul-20 16:13 UTC
[R] Convert Unix (Epoch) timestamp to DD/MM/YY and HH:MM:SS
Here is a function I use to convert a numeric value of the UNIX time to POSIXct unix2POSIXct <- function (time) structure(time, class c("POSIXt", "POSIXct")) On Tue, Jul 20, 2010 at 9:26 AM, Jim Hargreaves <james at ipec.co.uk> wrote:> Dear List, > > After much searching with no success, I would like to ask how I can convert > a unix/POSIX time (seconds since Jan 01, 1970) into a string like > "01/01/1970 00:00" > > This is probably easily done with a system(date...) but it would be great if > I could do it in R. > > Kind Regards, > Jim Hargreaves > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?