【发布时间】:2019-02-15 14:44:09
【问题描述】:
我想从日期时间中提取小时/分钟/秒。示例数据框:
df <- structure(list(Study_date_time_PACS = structure(c(1515146548, 1515146548, 1514970658, 1514970658, 1515151732, 1515151732, 1517476589, 1517476589, 1543848246, 1543848246),
class = c("POSIXct", "POSIXt"),
tzone = "UTC")),
.Names = "Study_date_time",
row.names = c(NA, -10L),
class = c("tbl_df", "tbl", "data.frame"))
print(df)
# A tibble: 10 x 1
Study_date_time
<dttm>
1 2018-01-05 10:02:28
2 2018-01-05 10:02:28
3 2018-01-03 09:10:58
4 2018-01-03 09:10:58
5 2018-01-05 11:28:52
6 2018-01-05 11:28:52
7 2018-02-01 09:16:29
8 2018-02-01 09:16:29
9 2018-12-03 14:44:06
10 2018-12-03 14:44:06
所以我运行了这段代码,但它在“小时”上增加了一小时?我怎样才能解决这个问题。我想它一定是夏天的东西......
library(lubridate)
df %>%
mutate(hour_min = hms::as.hms(Study_date_time))
# A tibble: 10 x 2
Study_date_time hour_min
<dttm> <time>
1 2018-01-05 10:02:28 11:02
2 2018-01-05 10:02:28 11:02
3 2018-01-03 09:10:58 10:10
4 2018-01-03 09:10:58 10:10
5 2018-01-05 11:28:52 12:28
6 2018-01-05 11:28:52 12:28
7 2018-02-01 09:16:29 10:16
8 2018-02-01 09:16:29 10:16
9 2018-12-03 14:44:06 15:44
10 2018-12-03 14:44:06 15:44
【问题讨论】: