Skip to contents

Converts a POSIXct or POSIXlt value to a "YYYY-MM-DD HH:MM:SS" string in UTC. Character values are passed through unchanged. Returns NULL when x is NULL.

Usage

format_timestamp(x, arg = rlang::caller_arg(x))

Arguments

x

A POSIXct, POSIXlt, or character timestamp, or NULL.

arg

Argument name for error messages. Defaults to the name of x in the calling frame.

Value

A character string, or NULL.

Examples

format_timestamp(as.POSIXct("2024-01-15 10:30:00", tz = "UTC"))
#> [1] "2024-01-15 10:30:00"
format_timestamp("2024-01-15 10:30:00")
#> [1] "2024-01-15 10:30:00"