如何检查时间是正数还是负数并将其与固定时间进行比较
How do I check if time is positive or negative and compare it with fixed time
时间不是数字数据类型。那么我该如何检查 if
- 正时
- 将时间与某个固定时间值进行比较
library(lubridate)
t = as_hms(Sys.time())
# question 1 - check if t is positive or negative
# question 2 - compare with time 11:23:01
加载包 lubridate
。然后确保您的日期具有 date
格式。如果不是,用lubridate::as_datetime(object)
函数转换。
那么,所有“经典”功能都将适用:
as_datetime(Sys.time()) > 0
[1] TRUE
并比较两个日期:
t <- as_datetime(Sys.time())
e <- as_datetime("2021-08-01")
> e > t
[1] TRUE
> e - t
Time difference of 30.38764 days
时间不是数字数据类型。那么我该如何检查 if
- 正时
- 将时间与某个固定时间值进行比较
library(lubridate)
t = as_hms(Sys.time())
# question 1 - check if t is positive or negative
# question 2 - compare with time 11:23:01
加载包 lubridate
。然后确保您的日期具有 date
格式。如果不是,用lubridate::as_datetime(object)
函数转换。
那么,所有“经典”功能都将适用:
as_datetime(Sys.time()) > 0
[1] TRUE
并比较两个日期:
t <- as_datetime(Sys.time())
e <- as_datetime("2021-08-01")
> e > t
[1] TRUE
> e - t
Time difference of 30.38764 days