当前位置:网站首页>R 17 date format exercise
R 17 date format exercise
2022-06-10 07:00:00 【THE ORDER】
> x=as.Date("1970-01-02")# Date format
> x
[1] "1970-01-02"
> class(x)
[1] "Date"
> unclass(x)
[1] 1
> as.Date("2018/01/24")
[1] "2018-01-24"
> x=as.POSIXct("2020-01-24 10:30:00")# Convert to time format Restore to the number of seconds
> x1=as.POSIXlt("2020-01-24 10:30:00")# After restore, there is a large list
> unclass(x)
[1] 1579833000
attr(,"tzone")
[1] ""
> unclass(x1)
$sec
[1] 0
$min
[1] 30
$hour
[1] 10
$mday
[1] 24
$mon
[1] 0
$year
[1] 120
$wday
[1] 5
$yday
[1] 23
$isdst
[1] 0
$zone
[1] "CST"
$gmtoff
[1] NA
> ?DateTimeClasses# View help documents
> x1$yday+1# Draw days
[1] 24
> weekdays(x)# Day of the week
[1] " Friday "
> months(x)# Return months
[1] " January "
> quarters(x)# Return to month
[1] "Q1"
> Sys.Date()# Return system date
[1] "2022-03-02"
> Sys.time()# Return to system time
[1] "2022-03-02 10:13:40 CST"
> date=c("01 10, 2012 10:40","12 09, 2011 09:10")
> date
[1] "01 10, 2012 10:40" "12 09, 2011 09:10"
> x=as.POSIXct(date,format="%m %d, %Y %H:%M")# Returns the standard format
> class(x)# Subclass "POSIXct" Parent class "POSIXt"
[1] "POSIXct" "POSIXt"
> t1=as.Date("2016-03-01")
> t2=as.Date("2016-02-28")
> t1-t2# Get the time difference
Time difference of 2 days
> t3=as.POSIXct("2015-03-12 12:00:00")
> t4=Sys.time()
> class(t4)
[1] "POSIXct" "POSIXt"
> t4-t3# Decimals are displayed
Time difference of 2546.926 days
> t4-t2# Different formats cannot be divided
[1] "2022-03-02 05:32:41 CST"
Warning message:
Incompatible methods ("-.POSIXt", "-.Date") for "-"
> as.numeric(t4-t3)
[1] 2546.926
> difftime(t4,t3)#t4-t3,units="weeks"units Return unit
Time difference of 2546.926 days
> difftime(t4,t3,units="mins")#t4-t3,units="weeks"units Return unit
Time difference of 3667574 mins
> ?seq
> l=seq(t3,t4,"year")# A sequence of equal differences t3 To t4
> l=length(l)
> l
[1] 7
> seq(t3,by="-2 month",length.out=12)# Push forward twice , The length is 2
[1] "2015-03-12 12:00:00 CST" "2015-01-12 12:00:00 CST" "2014-11-12 12:00:00 CST" "2014-09-12 12:00:00 CST" "2014-07-12 12:00:00 CST"
[6] "2014-05-12 12:00:00 CST" "2014-03-12 12:00:00 CST" "2014-01-12 12:00:00 CST" "2013-11-12 12:00:00 CST" "2013-09-12 12:00:00 CST"
[11] "2013-07-12 12:00:00 CST" "2013-05-12 12:00:00 CST"
>
> as.Date("2010/11/04")# Into time
[1] "2010-11-04"
> as.Date("11-04/2010",format="%m-%d/%Y") # Convert to standard format
[1] "2010-11-04"
> ts=Sys.Date()# system time
> class(ts)
[1] "Date"
> weekdays(ts)# What day
[1] " Wednesday "
> months(ts)
[1] " March "
> quarters(ts)# quarter
[1] "Q1"
> as.POSIXct("11-04 2016,33:59 23h",format="%m-%d %Y,%M:%S %Hh")# A standard format
[1] "2016-11-04 23:33:59 CST"
> t=strptime("11-04 2016,33m59s 23h",format="%m-%d %Y,%Mm%Ss %Hh")## Convert to standard format
> l=as.POSIXct("1986-11-04 02:00:00")# Character to time
> difftime(t,l,units="secs")# Phase difference length
Time difference of 946848839 secs
> difftime(t,l,units="mins")
Time difference of 15780814 mins
> difftime(t,l,units = "hours")
Time difference of 263013.6 hours
> difftime(t,l,unit="days")
Time difference of 10958.9 days
> length(seq(l,t,"month"))# Second difference
[1] 361
> length(seq(l,t,"year"))
[1] 31
> seq(t,by="-1 month",length.out=12)# Push forward -1 Months , The length is 12
[1] "2016-11-04 23:33:59 CST" "2016-10-04 23:33:59 CST" "2016-09-04 23:33:59 CST" "2016-08-04 23:33:59 CST" "2016-07-04 23:33:59 CST"
[6] "2016-06-04 23:33:59 CST" "2016-05-04 23:33:59 CST" "2016-04-04 23:33:59 CST" "2016-03-04 23:33:59 CST" "2016-02-04 23:33:59 CST"
[11] "2016-01-04 23:33:59 CST" "2015-12-04 23:33:59 CST"
边栏推荐
- TeleyeControlor V8.7 修复广域网上线 增加显示延时功能
- Read in one second: the practical operation of increasing capital and shares of enterprises!
- Deploy MySQL based on statefulset in kubernetes (Part 2)
- BOM browser object model
- 一本通1258.数字金字塔 题解 动态规划
- Dream notes 0610
- 618. How to prepare for the great promotion
- POC_ Jenkins
- Saccadenet: use corner features to fine tune the two stage prediction frame | CVPR 2020
- 2022-2027 (New Edition) report on the prospect and future development of China's property rights trading industry
猜你喜欢

Applet: scroll to the top of the page or an element position

Matlab: 多项式表示及其基本运算

R语言数据处理:tidyr包学习

POC_ Jenkins
![[econometrics] instrumental variable estimation and two-stage least square method](/img/b2/c43c2e7263e759bb25638ca53dc992.jpg)
[econometrics] instrumental variable estimation and two-stage least square method

TeleyeControlor V8.69 重构键盘记录功能发布 By:Yose

解析:稳定币不是“稳定的币”,其本质是一种产品

小程序:滚动到页面顶部或者某个元素位置

【动态规划】博弈论:取石子游戏合集

You can have zongzi if you want, but you have to go through my authentication and authorization
随机推荐
【动态规划】LeetCode1092. 最短公共超序列
TeleyeControlor V8.69 重构键盘记录功能发布 By:Yose
[width first search] the shortest path in leetcode1091 binary matrix
leetcode. 38 --- appearance series
Around ifelse and business logic
Tap series article 2 | Tanzu application platform v1.1 installation and configuration steps
Why can't lldb print view bounds? - Why can't LLDB print view. bounds?
Local storage of JS data interaction
29. solution for 300ms delay time of click event at mobile terminal
Instagram CEO: "Apple iPad is not very popular, and it is not worth developing an exclusive version of the app"
Scala fastjson modifying key or value
Oriental Star Hotel Management Catering project - query function
小程序:通过getCurrentPages获取当前页面路由信息
Shardingsphere practice (6) - elastic scaling
June 9, 2022: each meeting is given a start and end time. If there is any conflict between the subsequent meeting and the previous meeting, the conflicting and previous meeting will be completely canc
Applet: get the current page routing information through getcurrentpages
CMD of Jerry's AI protocol_ SET_ BLE_ Format of visibility command [chapter]
电脑新加内存条后 游戏崩溃 浏览器卡死 电脑蓝屏
tensorflow实验九----------泰坦尼克号
TeleyeControlor V8.16发布 完成注册表功能