我正在计算两个日期时间的差异,使用difftime
函数R
并得到错误的答案,这是代码
t1 <- as.POSIXct("7/18/2005 8:30:00", format = "%m/%d/%Y %H:%M:%S")
t2 <- as.POSIXct("10/30/2005 8:30:00", format = "%m/%d/%Y %H:%M:%S")
difftime(t2,t1,units = "hours")
我得到以下答案
Time difference of 2497 hours
我知道这是错误的,因为两者都t1
具有t2
相同的time
值,因此它们应该以 24 小时的精确倍数分隔(即正确答案是 2496 小时,而不是 2497 - 也由其他工具(如 excel、google 表格)确认)。
任何想法,为什么R
给我错误的结果?