Passer au contenu

Converts a vector of dates or date-time representations into a POSIXct object in the UTC time zone. The function accepts POSIXct, Date, or character inputs and attempts to parse character values using a predefined set of common date and date-time formats. Values that cannot be parsed are returned as NA.

Utilisation

to_posix(v)

Arguments

v

A vector of dates or date-time values. Can be of class POSIXct, Date, or character.

Valeur de retour

A vector of class POSIXct with time zone set to UTC. Unparsable values are returned as NA.

Détails

If v is already a POSIXct object, it is returned unchanged. If v is a Date object, it is converted to POSIXct with an implicit time of midnight (00:00:00) in UTC. Character inputs are parsed iteratively using several common date and date-time formats until all possible values are converted.

Exemples

if (FALSE) { # \dontrun{
to_posix("2024-03-15 14:30")
to_posix(c("15/03/2024", "2024-03-16 08:00"))
to_posix(as.Date("2024-03-15"))
} # }