Rには日付、日時、時差のクラスが付属しています。参照?Dates
、 ?DateTimeClasses
、 ?difftime
し、さらに文書化のためのそれらのドキュメントの「関連項目」セクションに従ってください。関連するドキュメント: 日付と日付 - 時刻クラス 。
date-timeクラスPOSIXctは、 1970-01-01 00:00:00 UTC
年1970-01-01 00:00:00 UTC
UNIXエポック以降の時間を秒単位で格納し1970-01-01 00:00:00 UTC
。これは、 Sys.Time()
現在時刻をSys.Time()
するときに返される形式です。
日時クラス。日、月、年、時、分、秒などのリストを格納します。これはstrptime
によって返される形式です。
Date唯一の日付クラスで、日付を浮動小数点数として格納します。
UNIXのtidyverseと世界では、POSIXctが唯一の選択肢です。これは、POSIXltよりも速く、メモリを消費しません。
origin = as.POSIXct("1970-01-01 00:00:00", format ="%Y-%m-%d %H:%M:%S", tz = "UTC")
origin
## [1] "1970-01-01 UTC"
origin + 47
## [1] "1970-01-01 00:00:47 UTC"
as.numeric(origin) # At epoch
## 0
as.numeric(Sys.time()) # Right now (output as of July 21, 2016 at 11:47:37 EDT)
## 1469116057
posixlt = as.POSIXlt(Sys.time(), format ="%Y-%m-%d %H:%M:%S", tz = "America/Chicago")
# Conversion to POISXct
posixct = as.POSIXct(posixlt)
posixct
# Accessing components
posixlt$sec # Seconds 0-61
posixlt$min # Minutes 0-59
posixlt$hour # Hour 0-23
posixlt$mday # Day of the Month 1-31
posixlt$mon # Months after the first of the year 0-11
posixlt$year # Years since 1900.
ct = as.POSIXct("2015-05-25")
lt = as.POSIXlt("2015-05-25")
object.size(ct)
# 520 bytes
object.size(lt)
# 1816 bytes