Skip to contents

as_datetimeoffset() coerces to datetimeoffset() objects.

Usage

as_datetimeoffset(x, ...)

# S3 method for class 'datetimeoffset'
as_datetimeoffset(x, ...)

# S3 method for class 'Date'
as_datetimeoffset(x, tz = NA_character_, ...)

# Default S3 method
as_datetimeoffset(x, ...)

# S3 method for class 'integer'
as_datetimeoffset(x, ...)

# S3 method for class 'numeric'
as_datetimeoffset(x, ...)

# S3 method for class 'POSIXt'
as_datetimeoffset(x, ...)

# S3 method for class 'character'
as_datetimeoffset(x, tz = NA_character_, ...)

# S3 method for class 'nanotime'
as_datetimeoffset(x, tz = "GMT", ...)

# S3 method for class 'partial_time'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_year_month_day'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_year_month_weekday'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_iso_year_week_day'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_year_quarter_day'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_year_day'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_naive_time'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_sys_time'
as_datetimeoffset(x, ...)

# S3 method for class 'clock_zoned_time'
as_datetimeoffset(x, ...)

Arguments

x

An R object that can reasonably be coerced to a datetimeoffset() object such as a string in pdfmark date or ISO 8601 datetime formats or something with an as.POSIXct() method.

...

Further arguments to certain methods.

tz

Time zone to use for the conversion. Ignored by as_datetimeoffset.Date(). Generally need not be a single value.

Value

A datetimeoffset() vector

Examples

# ISO 8601 examples
as_datetimeoffset("2020-05-15")
#> <datetimeoffset[1]>
#> [1] 2020-05-15
as_datetimeoffset("20200515")
#> <datetimeoffset[1]>
#> [1] 2020-05-15
as_datetimeoffset("2020-05-15T08:23:16")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16
as_datetimeoffset("20200515T082316")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16
as_datetimeoffset("2020-05-15T08:23:16.003Z")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16.003Z
as_datetimeoffset("20200515T082316Z")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16Z
as_datetimeoffset("2020-05-15T08:23:16+03:30")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16+03:30
as_datetimeoffset("20200515T082316+0330")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16+03:30

# Misc supported `as.POSIXlt()` `tryFormats` examples
as_datetimeoffset("2020/05/15 08:23:16")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16

# pdfmark datetime examples
as_datetimeoffset("D:20200515")
#> <datetimeoffset[1]>
#> [1] 2020-05-15
as_datetimeoffset("D:20200515082316")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16
as_datetimeoffset("D:20200515082316+03'30'")
#> <datetimeoffset[1]>
#> [1] 2020-05-15T08:23:16+03:30

as_datetimeoffset(Sys.time())
#> <datetimeoffset[1]>
#> [1] 2025-03-24T09:52:30.318391-07:00[America/Los_Angeles]