Data and Times

Data and Time

> d1 <- Sys.Date() 
> class(d1)
[1] "Date"
> unclass(d1)
[1] 16978
> d2 <- as.Date("1969-01-01")
> unclass(d2)
[1] -365

| As you may have anticipated, you get a negative number. In this case, it’s -365, since 1969-01-01 is exactly one calendar

| year (i.e. 365 days) BEFORE 1970-01-01.

> t1 <- Sys.time()
> t1
[1] "2016-06-26 15:28:49 CST"
> class(t1)
[1] "POSIXct" "POSIXt" 
> class(t1)
[1] "POSIXct" "POSIXt" 
> t2
[1] "2016-06-26 15:30:09 CST"
> class(t2)
[1] "POSIXlt" "POSIXt"  
> t2
[1] "2016-06-26 15:30:09 CST"
> unclass(t2)
$sec
[1] 9.688538

$min
[1] 30

$hour
[1] 15

$mday
[1] 26

$mon
[1] 5

$year
[1] 116

$wday
[1] 0

$yday
[1] 177

$isdst
[1] 0

$zone
[1] "CST"

$gmtoff
[1] 28800

attr(,"tzone")
[1] ""    "CST" "CDT"

> str(unclass(t2))
List of 11
 $ sec   : num 9.69
 $ min   : int 30
 $ hour  : int 15
 $ mday  : int 26
 $ mon   : int 5
 $ year  : int 116
 $ wday  : int 0
 $ yday  : int 177
 $ isdst : int 0
 $ zone  : chr "CST"
 $ gmtoff: int 28800
 - attr(*, "tzone")= chr [1:3] "" "CST" "CDT"

| Now that we have explored all three types of date and
time objects, let’s look at a few functions that extract useful

| information from any of these objects – weekdays(),
months(), and quarters().

| The same line of thinking applies to addition and the other comparison operators. If you want more control over the units

| when finding the above difference in times, you can use difftime(), which allows you to specify a ‘units’ parameter.

| Use difftime(Sys.time(), t1, units = ‘days’) to find the amount of time in DAYS that has passed since you created t1.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值