格式化日期
要格式化 Dates,我們使用 format(date, format="%Y-%m-%d") 函式與 POSIXct(由 as.POSIXct() 給出)或 POSIXlt(由 as.POSIXlt() 給出)
d = as.Date("2016-07-21") # Current Date Time Stamp
format(d,"%a") # Abbreviated Weekday
## [1] "Thu"
format(d,"%A") # Full Weekday
## [1] "Thursday"
format(d,"%b") # Abbreviated Month
## [1] "Jul"
format(d,"%B") # Full Month
## [1] "July"
format(d,"%m") # 00-12 Month Format
## [1] "07"
format(d,"%d") # 00-31 Day Format
## [1] "21"
format(d,"%e") # 0-31 Day Format
## [1] "21"
format(d,"%y") # 00-99 Year
## [1] "16"
format(d,"%Y") # Year with Century
## [1] "2016"
有關更多資訊,請參閱 ?strptime。