【问题标题】:How to format the times and get a time delta in R using chron如何使用 chron 格式化时间并在 R 中获取时间增量
【发布时间】:2022-08-02 23:25:03
【问题描述】:

我有两个时间点,我想获得一个时间增量(注意我的时间有毫秒)。我尝试使用 Chron 包:

library(chron)
t1<- \'2022/06/28 - 10:45:40:124\'
t2<-\'2022/06/28 - 10:54:50:193\'
chron(t1, format=\'%Y/%m/%d - %H:%M:%S:%f\')

但我收到以下错误:

Error in parse.format(format): unrecognized format %Y/%m/%d - %H:%M:%S:%f
Traceback:

1. chron(\"2022/06/28 - 10:45:40:124\", format = \"%Y/%m/%d - %H:%M:%S:%f\")
2. convert.dates(dates., format = fmt, origin. = origin.)
3. parse.format(format)
4. stop(paste(\"unrecognized format\", format))

我的实施有什么问题?

谢谢您的回答。

    标签: r datetime time timedelta chron


    【解决方案1】:

    我们可以使用来自parsedateparse_date

    library(parsedate)
     parse_date(t1) - parse_date(t2)
    Time difference of -9.166667 mins
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-24
      • 2020-01-09
      • 2019-06-30
      相关资源
      最近更新 更多