Learn R Programming

CFtime (version 1.6.0)

as_timestamp: Create a vector that represents CF timestamps

Description

This function generates a vector of character strings or POSIXcts that represent the date and time in a selectable combination for each offset.

Usage

as_timestamp(t, format = NULL, asPOSIX = FALSE)

Value

A character vector where each element represents a moment in time according to the format specifier.

Arguments

t

The CFTime instance that contains the offsets to use.

format

character. A character string with either of the values "date" or "timestamp". If the argument is not specified, the format used is "timestamp" if there is time information, "date" otherwise.

asPOSIX

logical. If TRUE, for "standard", "gregorian" and "proleptic_gregorian" calendars the output is a vector of POSIXct - for other calendars an error will be thrown. Default value is FALSE.

Details

The character strings use the format YYYY-MM-DDThh:mm:ss±hhmm, depending on the format specifier. The date in the string is not necessarily compatible with POSIXt - in the 360_day calendar 2017-02-30 is valid and 2017-03-31 is not.

For the "proleptic_gregorian" calendar the output can also be generated as a vector of POSIXct values by specifying asPOSIX = TRUE. The same is possible for the "standard" and "gregorian" calendars but only if all timestamps fall on or after 1582-10-15.

See Also

The CFTime format() method gives greater flexibility through the use of strptime-like format specifiers.

Examples

Run this code
t <- CFtime("hours since 2020-01-01", "standard", seq(0, 24, by = 0.25))
as_timestamp(t, "timestamp")

t2 <- CFtime("days since 2002-01-21", "standard", 0:20)
tail(as_timestamp(t2, asPOSIX = TRUE))

tail(as_timestamp(t2))

tail(as_timestamp(t2 + 1.5))

Run the code above in your browser using DataLab