【问题标题】:Format a date and time string [closed]格式化日期和时间字符串
【发布时间】:2017-06-14 09:12:05
【问题描述】:

我需要转换一个字符串如:

"19480804 14:00"

到如下格式的日期:

"Aug 4th, 1948 2 PM"

【问题讨论】:

    标签: r date formatting


    【解决方案1】:

    所有信息:https://www.stat.berkeley.edu/~s133/dates.html

    你必须把字符串改成日期格式,例如:

    date <-("19480804 14:00")
    x <- strptime(date,"%Y%m%d %H:%M")
    

    输出:

    [1] "1948-08-04 14:00:00 CEST"
    

    另外:

    format(x, format="%b %d, %Y %I %p")
    

    和输出:

    "Aug 04, 1948 02 PM"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      • 1970-01-01
      相关资源
      最近更新 更多