Sys.time(),Sys.Date()
Sys.Date()用于获取当前系统日期。
> Sys.Date()
[1] "2022-05-10"
Sys.time()用于获取当前系统时间,具体到秒。
> Sys.time()
[1] "2022-05-10 19:15:58 CST"
> options(digits.secs = 3)
> Sys.time()
[1] "2022-05-10 19:30:47.253 CST"
options()可以用来定义全局默认参数。这里用来设置时间默认保留的小数位。options()的用法可以参考https://www.cnblogs.com/awishfullyway/p/6610527.html
format()可用于将日期,时间格式化,也可用于单独提取需要的时间信息
> format(Sys.time(), "%a %b %d %X %Y")
[1] "周二 5月 10 19:32:28 2022"
> format(Sys.time(), "%H:%M:%S")
[1] "19:42:58"
> format(Sys.time(), "%H:%M:%OS3") #“% OS3”表示秒数小数位取3位。
[1] "19:36:13.853"
>#定义默认保留4位小数
> options(digits.secs = 4)
> format(Sys.time(), "%H:%M:%OS")
> #“% OS”表示秒数小数位取默认位数。
[1] "19:54:18.7703"
> format(Sys.time(), '%Y')
[1] "2022"
> format(Sys.time(), '%y')
[1] "22"
> format(Sys.time(), '%m')
[1] "05"
> format(Sys.time(), '%B')
[1] "五月"
> format(