toPOSIXct: Parse POSIXct objects from input data

View source: R/RcppExports.R

toPOSIXctR Documentation

Parse POSIXct objects from input data


This function uses the Boost Date_Time library to parse datetimes (and dates) from strings, integers or even numeric values (which are cast to strings internall). 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.


toPOSIXct(x, tz = "UTC")



A vector of type character, integer or numeric with date(time) expressions to be parsed and converted.


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


A number of fixed formats are tried in succession. These include the standard ISO format ‘YYYY-MM-DD HH:MM:SS’ as well as different local variants including several forms popular in the United States. Two-digits years and clearly ambigous formats such as ‘03/04/05’ are ignored. In the case of parsing failure a NA value is returned.

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.


A vector of ‘POSIXct’ elements.


Dirk Eddelbuettel

See Also

The funtion in the anytime package which is a more finished. variant which is based on the initial work with function, and taken into its own package.


## See the source code (hah!) for a full list of formats
times <- c("2004-03-21 12:45:33.123456",
          "2004/03/21 12:45:33.123456",
          "20040321 124533.123456",
          "21.03.2004 12:45:33.123456", 
          "03/21/2004 12:45:33.123456",
          "03-21-2004 12:45:33.123456", 

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