格式化和打印日期时间对象
# test date-time object
options(digits.secs = 3)
d = as.POSIXct("2016-08-30 14:18:30.58", tz = "UTC")
format(d,"%S") # 00-61 Second as integer
## [1] "30"
format(d,"%OS") # 00-60.99… Second as fractional
## [1] "30.579"
format(d,"%M") # 00-59 Minute
## [1] "18"
format(d,"%H") # 00-23 Hours
## [1] "14"
format(d,"%I") # 01-12 Hours
## [1] "02"
format(d,"%p") # AM/PM Indicator
## [1] "PM"
format(d,"%z") # Signed offset
## [1] "+0000"
format(d,"%Z") # Time Zone Abbreviation
## [1] "UTC"
有关格式字符串的详细信息,请参阅 ?strptime
以及其他格式。