【发布时间】:2021-12-22 05:03:55
【问题描述】:
我的数据集包含这样的日期:my_date = c("December 02, 2017 at 07:33PM")。
格式应为"%B-%d-%Y-%I:%M-%p"。
我已经删除了“at”:
library(tm)
stopwords = c("at")
my_date = removeWords(my_date, stopwords).
我现在如何将日期转换为我想要的格式。非常感谢您的帮助。
【问题讨论】:
我的数据集包含这样的日期:my_date = c("December 02, 2017 at 07:33PM")。
格式应为"%B-%d-%Y-%I:%M-%p"。
我已经删除了“at”:
library(tm)
stopwords = c("at")
my_date = removeWords(my_date, stopwords).
我现在如何将日期转换为我想要的格式。非常感谢您的帮助。
【问题讨论】:
psx <- as.POSIXct("December 02, 2017 at 07:33PM", format = "%B %d, %Y at %I:%M%p")
psx
# [1] "2017-12-02 19:33:00 EST"
format(psx, format = "%B-%d-%Y-%I:%M-%p")
# [1] "December-02-2017-07:33-PM"
【讨论】: