Learn R Programming

datetimeoffset (version 1.0.0)

getters: Get datetime components

Description

Getter methods for datetimeoffset() objects.

Usage

# S3 method for datetimeoffset
get_year(x)

# S3 method for datetimeoffset get_month(x)

# S3 method for datetimeoffset get_day(x)

# S3 method for datetimeoffset get_hour(x)

# S3 method for datetimeoffset get_minute(x)

# S3 method for datetimeoffset get_second(x)

# S3 method for datetimeoffset get_nanosecond(x)

get_subsecond_digits(x)

# S3 method for datetimeoffset get_subsecond_digits(x)

# S3 method for default get_subsecond_digits(x)

get_hour_offset(x)

# S3 method for datetimeoffset get_hour_offset(x)

# S3 method for default get_hour_offset(x)

# S3 method for POSIXt get_hour_offset(x)

get_minute_offset(x)

# S3 method for datetimeoffset get_minute_offset(x)

# S3 method for default get_minute_offset(x)

# S3 method for POSIXt get_minute_offset(x)

get_tz(x)

# S3 method for datetimeoffset get_tz(x)

# S3 method for Date get_tz(x)

# S3 method for POSIXt get_tz(x)

# S3 method for clock_zoned_time get_tz(x)

# S3 method for default get_tz(x)

Value

The component

Arguments

x

A datetime object.

Details

We implement datetimeoffset() support for the following S3 methods from clock:

  • get_year()

  • get_month()

  • get_day()

  • get_hour()

  • get_minute()

  • get_second()

  • get_nanosecond()

We also implemented new S3 getter methods:

  • get_subsecond_digits()

  • get_hour_offset()

  • get_minute_offset()

  • get_tz()

We also implement datetimeoffset() support for the following S3 methods from lubridate:

  • year()

  • month()

  • mday()

  • hour()

  • minute()

  • second()

  • tz()

  • date()

Examples

Run this code
library("clock")
if ("Europe/Paris" %in% OlsonNames()) {
  dt <- as_datetimeoffset("1918-11-11T11:11:11.1234+00:00[Europe/Paris]")
} else {
  dt <- as_datetimeoffset("1918-11-11T11:11:11.1234")
}
get_year(dt)
get_month(dt)
get_day(dt)
get_hour(dt)
get_minute(dt)
get_second(dt)
get_nanosecond(dt)
get_subsecond_digits(dt)
get_hour_offset(dt)
get_minute_offset(dt)
get_tz(dt)
if (require("lubridate")) {
  paste0(year(dt), "-", month(dt), "-", day(dt),
         "T", hour(dt), ":", minute(dt), ":", second(dt),
         "[", tz(dt), "]")
}

Run the code above in your browser using DataLab