Learn R Programming

clock (version 0.7.1)

clock-getters: Calendar getters

Description

This family of functions extract fields from a calendar vector. Each calendar has its own set of supported getters, which are documented on their own help page:

  • year-month-day

  • year-month-weekday

  • year-week-day

  • iso-year-week-day

  • year-quarter-day

  • year-day

There are also convenience methods for extracting certain components directly from R's native date and date-time types.

  • dates (Date)

  • date-times (POSIXct / POSIXlt)

Usage

get_year(x)

get_quarter(x)

get_month(x)

get_week(x)

get_day(x)

get_hour(x)

get_minute(x)

get_second(x)

get_millisecond(x)

get_microsecond(x)

get_nanosecond(x)

get_index(x)

Value

The component.

Arguments

x

[object]

An object to get the component from.

Details

You cannot extract components directly from a time point type, such as sys-time or naive-time. Convert it to a calendar type first. Similarly, a zoned-time must be converted to either a sys-time or naive-time, and then to a calendar type, to be able to extract components from it.

Examples

Run this code
x <- year_month_day(2019, 1:3, 5:7, 1, 20, 30)
get_month(x)
get_day(x)
get_second(x)

Run the code above in your browser using DataLab