Last active
October 21, 2015 18:54
-
-
Save scw/f42d22a09e6e87d0d85f to your computer and use it in GitHub Desktop.
Convert an FGDB sourced datetime column to a POSIXct type in R
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('arcgisbinding') | |
arc.check_product() | |
# a FGDB source with a column 'datetime' containing our datetime field | |
d <- arc.open('a/fgdb/source') | |
df <- arc.select(d, 'datetime') | |
# convert from 1899-12-30 00:00 to UNIX Epoch, in seconds | |
as.unix.epoch <- (df$datetime[1]-25569)*86400 | |
# convert to POSIXct object, albeit with invalid TZ | |
ct <- as.POSIXct(as.unix.epoch, origin="1970-1-1", tz="GMT") | |
# fix the TZ | |
fmt <- paste("%Y-%m-%d %H:%M:%S%z ", Sys.timezone()) | |
ct.with.tz <- as.POSIXct(format(ct, fmt), usetz=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment