По указанной ссылке @MichaelChirico мы можем использовать unix_timestamp
, to_timestamp
и to_utc_timestamp
для преобразования строки в объект datetime.
time_stamp <- c("2017-12-06T20:08:56.000", "2017-11-08T12:09:37.000",
"2017-12-06T20:08:56.123", "2017-11-08T12:09:37.456")
time_tbl <- copy_to(sc, tibble(timestamp=time_stamp))
# > time_tbl
# # Source: spark<?> [?? x 1]
# timestamp
# <chr>
# 1 2017-12-06T20:08:56.000
# 2 2017-11-08T12:09:37.000
# 3 2017-12-06T20:08:56.123
# 4 2017-11-08T12:09:37.456
time_tbl %>%
mutate(ctimes = unix_timestamp(timestamp, "yyyy-MM-dd'T'HH:mm:ss.SSS"))
# # Source: spark<?> [?? x 2]
# timestamp ctimes
# <chr> <dbl>
# 1 2017-12-06T20:08:56.000 1512554936
# 2 2017-11-08T12:09:37.000 1510106977
# 3 2017-12-06T20:08:56.123 1512554936
# 4 2017-11-08T12:09:37.456 151010697
time_tbl %>%
mutate(ctimes = to_timestamp(timestamp, "yyyy-MM-dd'T'HH:mm:ss.SSS"))
# # Source: spark<?> [?? x 2]
# timestamp ctimes
# <chr> <dttm>
# 1 2017-12-06T20:08:56.000 2017-12-06 10:08:56
# 2 2017-11-08T12:09:37.000 2017-11-08 02:09:37
# 3 2017-12-06T20:08:56.123 2017-12-06 10:08:56
# 4 2017-11-08T12:09:37.456 2017-11-08 02:09:37
time_tbl %>%
mutate(ctimes = to_utc_timestamp(timestamp, "yyyy-MM-dd'T'HH:mm:ss.SSS"))
# #Source: spark<?> [?? x 2]
# timestamp ctimes
# <chr> <dttm>
# 1 2017-12-06T20:08:56.000 2017-12-06 10:08:56
# 2 2017-11-08T12:09:37.000 2017-11-08 02:09:37
# 3 2017-12-06T20:08:56.123 2017-12-06 10:08:56
# 4 2017-11-08T12:09:37.456 2017-11-08 02:09:37