alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

【862】as.Date in R programming

ref: R语言——日期时间处理

ref: as.Date: Date Conversion Functions to and from Character

ref: Date Formats in R


as.Date()it can change a normal string into a date format.

format()It can extract the specific date format from a date string.

Example:

> d = "2020-02-21"
> format(as.Date(d), format="%B, %Y")
[1] "February, 2020"
> format(as.Date(d), format="%d %B, %Y")
[1] "21 February, 2020"
> format(as.Date(d), format="%d %B, %Y, %A")
[1] "21 February, 2020, Friday"

Date Formats

Conversion specification Description Example
%a Abbreviated weekday Sun, Thu
%A Full weekday Sunday, Thursday
%b or %h Abbreviated month May, Jul
%B Full month May, July
%d Day of the month
01-31
27, 07
%j Day of the year
001-366
148, 188
%m Month
01-12
05, 07
%U Week
01-53
with Sunday as first day of the week
22, 27
%w Weekday
0-6
Sunday is 0
0, 4
%W Week
00-53
with Monday as first day of the week
21, 27
%x Date, locale-specific  
%y Year without century
00-99
84, 05
%Y Year with century
on input:
00 to 68 prefixed by 20
69 to 99 prefixed by 19
1984, 2005
%C Century 19, 20
%D Date formatted %m/%d/%y 05/27/84, 07/07/05
%u Weekday
1-7
Monday is 1
7, 4
     
%n Newline on output or
Arbitrary whitespace on input
 
%t Tab on output or
Arbitrary whitespace on input
 

 

posted on   McDelfino  阅读(5)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-07-20 【616】安装 GDAL(rasterio)
点击右上角即可分享
微信分享提示