【问题标题】:Convert a character string in Format "%B-%d-%Y-%I:%M-%p" into a Date with Format "%Y%m%d" in R将格式为“%B-%d-%Y-%I:%M-%p”的字符串转换为格式为“%Y%m%d”的日期在R中
【发布时间】: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).

我现在如何将日期转换为我想要的格式。非常感谢您的帮助。

【问题讨论】:

    标签: r date


    【解决方案1】:
    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"
    

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 2017-09-23
      • 2013-09-09
      • 1970-01-01
      相关资源
      最近更新 更多