as_timestamp {CFtime}R Documentation

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(cf, format = NULL, asPOSIX = FALSE)

Arguments

cf

CFtime. 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 the result is NULL. 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 "standard", "gregorian" and "proleptic_gregorian" calendars the output can also be generated as a vector of POSIXct values by specifying asPOSIX = TRUE.

Value

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

See Also

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

Examples

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

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

tail(as_timestamp(cf2))

tail(as_timestamp(cf2 + 1.5))

[Package CFtime version 1.4.0 Index]