[R] Convert Unix (Epoch) timestamp to DD/MM/YY and HH:MM:SS
David Winsemius
dwinsemius at comcast.net
Tue Jul 20 15:42:45 CEST 2010
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
More information about the R-help
mailing list