Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_tod

Convert datetime to time-of-day


Description

Convert a datetime into a time of day expressed in hours, minutes or seconds from midnight in local time for a time zone. This conversion is useful when time-series data for different days needs to be compared or plotted based on the local time-of-day.

Usage

as_tod(x, unit.out = "hours", tz = NULL)

Arguments

x

a datetime object accepted by lubridate functions

unit.out

character string, One of "tod_time", "hours", "minutes", or "seconds".

tz

character string indicating time zone to be used in output.

Value

A numeric vector of the same length as x. If unit.out = "tod_time" an object of class "tod_time" which the same as for unit.out = "hours" but with the class attribute set, which dispatches to special format() nad print() methods.

See Also

Other Time of day functions: format.tod_time(), print.tod_time()

Examples

library(lubridate)
my_instants <- ymd_hms("2020-05-17 12:05:03") + days(c(0, 30))
my_instants
as_tod(my_instants)
as_tod(my_instants, unit.out = "tod_time")

photobiology

Photobiological Calculations

v0.10.10
GPL (>= 2)
Authors
Pedro J. Aphalo [aut, cre] (<https://orcid.org/0000-0003-3385-972X>), Titta K. Kotilainen [ctb] (<https://orcid.org/0000-0002-2822-9734>), Glenn Davis [ctb], Agnese Fazio [ctb]
Initial release
2022-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.