要格式化Dates我们使用format(date, format="%Y-%m-%d")函数无论是POSIXct(从给出的)或(从给出)as.POSIXct()POSIXltas.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。