Created
August 14, 2014 09:00
-
-
Save timyates/0b861301220f5b50b571 to your computer and use it in GitHub Desktop.
lubridate and ISO8601
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lubridate) | |
dates = c('2014-08-14T12:00:00+01:00', | |
'2014-08-14T14:46:34', | |
'2014-08-14T14:46:34.876', | |
'2014-08-14T14:46:34Z', | |
'2014-08-14T14:46:34-05:00', | |
'2014-08-14T14:46:34Z') | |
print(paste('Given', paste(dates, collapse=', '))) | |
posixDates = ymd_hms(dates) | |
print(paste('Parsed as', paste(posixDates, collapse=', '))) | |
secondsFromEpoch = as.numeric(posixDates) | |
print(paste('Can get seconds, not sure how to get ms', paste(secondsFromEpoch, collapse=', '))) | |
formatter = stamp('2013-01-01T06:00:00Z', quiet=T) | |
backToDates = formatter(as.POSIXct(secondsFromEpoch, origin='1970-01-01')) | |
print(paste('And converted back', paste(backToDates, collapse=', '))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment