as.Date(x, ...) ## Default S3 method: as.Date(x, ...) ## S3 method for class 'numeric': as.Date(x, origin, ...) ## S3 method for class 'character': as.Date(x, format = "", ...) ## S3 method for class 'factor': as.Date(x, ...) ## S3 method for class 'POSIXct': as.Date(x, tz = "UTC", ...) ## S3 method for class 'POSIXlt': as.Date(x, ...) ## S3 method for class 'date': as.Date(x, ...) ## S3 method for class 'dates': as.Date(x, ...)as.POSIXct(x, tz = "", ...) ## Default S3 method: as.POSIXct(x, tz = "", ...) ## S3 method for class 'numeric': as.POSIXct(x, tz = "", origin, ...) ## S3 method for class 'Date': as.POSIXct(x, ...) ## S3 method for class 'factor': as.POSIXct(x, ...) ## S3 method for class 'POSIXlt': as.POSIXct(x, tz = "", ...) ## S3 method for class 'date': as.POSIXct(x, ...) ## S3 method for class 'dates': as.POSIXct(x, ...)
as.POSIXlt(x, tz = "", ...) ## Default S3 method: as.POSIXlt(x, tz = "", ...) ## S3 method for class 'numeric': as.POSIXlt(x, tz = "", origin, ...) ## S3 method for class 'character': as.POSIXlt(x, tz = "", format, ...) ## S3 method for class 'factor': as.POSIXlt(x, ...) ## S3 method for class 'Date': as.POSIXlt(x, ...) ## S3 method for class 'POSIXct': as.POSIXlt(x, tz = "", ...) ## S3 method for class 'date': as.POSIXlt(x, ...) ## S3 method for class 'dates': as.POSIXlt(x, ...)
strptime(x, format, tz = "")
as.difftime(tim, format = "%X", units = "auto")
| x | any object to be converted to date-time. |
| format |
a character string specifying the date-time format; for example, "%Y-%m-%d" "%Y-%m-%d %H:%M" "%Y-%m-%d %H:%M:%S" "%Y-%m-%d %H:%M:%OS" "%Y-%m-%d %H:%M:%OS3" |
| tz | a character string specifying the time zone. |
| origin | a character string specifying the starting date-time. Must be provided for the numeric methods. |
| tim | any object to be converted to difftime. Usually character or numeric. |
| units | a character string specifying the time unit from "auto", "secs", "mins", "hours", "days", and "weeks". |
| ... | additional arguments. |
| as.Date.* | return a Date object representing the date. |
| as.POSIXct.* | return a POSIXct object representing the date-time. |
| as.POSIXlt.* | return a POSIXlt object representing the date-time. |
| strptime | return a POSIXlt object representing the date-time. |
| as.difftime | returns a difftime object representing the time interval. |
## convert to Date
as.Date(c("1900.01.01", "1970-01-01 00:00:00", "2038/01/19 03:14:08"))
as.Date("01/19/2038 03:14:08", format = "%m/%d/%Y %H:%M:%S")
as.Date(-1:1, origin = "1970-01-01")
as.Date(-1:1, origin = "1970-01-01 00:00:00")
as.Date(Sys.time())
as.Date(Sys.time(), tz = "Asia/Shanghai")
## convert to POSIXct
as.POSIXct(c("1900.01.01", "1970-01-01 00:00:00",
"2038/01/19 03:14:08"))
as.POSIXct("01/19/2038 03:14:08", format = "%m/%d/%Y %H:%M:%S",
tz = "Asia/Shanghai")
as.POSIXct(-1:1, origin = "1970-01-01")
as.POSIXct(-1:1, origin = "1970-01-01 00:00:00", tz = "Asia/Shanghai")
as.POSIXct(Sys.Date())
## convert to POSIXlt
as.POSIXlt(c("1900.01.01", "1970-01-01 00:00:00",
"2038/01/19 03:14:08"))
as.POSIXlt("01/19/2038 03:14:08", format = "%m/%d/%Y %H:%M:%S",
tz = "Asia/Shanghai")
as.POSIXlt(-1:1, origin = "1970-01-01")
as.POSIXlt(-1:1, origin = "1970-01-01 00:00:00", tz = "Asia/Shanghai")
as.POSIXlt(-1:1, origin = "1970-01-01 00:00:00", tz = "GMT")
as.POSIXlt(Sys.time())
as.POSIXlt(Sys.time(), tz = "Asia/Shanghai")
as.POSIXlt(Sys.time(), tz = "GMT")
as.POSIXlt(Sys.Date())
## convert to POSIXlt with strptime
strptime(c("1900.01.01", "1970-01-01 00:00:00", "2038/01/19 03:14:08"),
format = "")
strptime("01/19/2038 03:14:08", format = "%m/%d/%Y %H:%M:%S",
tz = "Asia/Shanghai")
strptime(Sys.time(), format = "")
strptime(Sys.time(), format = "%Y-%m-%d %H:%M:%S")
strptime(Sys.Date(), format = "")
## parse strings and numerics into difftime objects
as.difftime("0:1:0", format = "%H:%M:%S", units = "secs")
as.difftime("1", format = "%M", units = "secs")
as.difftime(1, units = "secs")