charToPOSIXct: Parse POSIXct objects from character variables

View source: R/RcppExports.R

charToPOSIXctR Documentation

Parse POSIXct objects from character variables

Description

This function uses the Boost Date_Time library to parse datetimes from strings. It returns a vector of POSIXct objects. These represent dates and time as (possibly fractional) seconds since the ‘epoch’ of January 1, 1970. A timezone can be set, if none is supplied ‘UTC’ is set.

Usage

charToPOSIXct(sv, tz = "UTC")

Arguments

sv

A vector of type character with datetime expressions in ISO format to be parsed and converted.

tz

A string with the timezone, defaults to ‘UTC’ if unset

Details

A single standard ISO format ‘YYYY-MM-DD HH:MM:SS’ (with optional trailing fractional seconds) is tried. In the case of parsing failure a NA value is returned. See the function toPOSIXct for more general input format

Fractional seconds are supported as well. As R itself only supports microseconds, the Boost compile-time option for nano-second resolution has not been enabled.

Value

A vector of ‘POSIXct’ elements.

Author(s)

Dirk Eddelbuettel

Examples

times <- c("2004-03-21 12:45:33.123456",
          "2004-03-21 12:45:34")
charToPOSIXct(times)

RcppBDT documentation built on Oct. 31, 2022, 1:07 a.m.