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.
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)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
my_instants <- ymd_hms("2020-05-17 12:05:03") + days(c(0, 30))
my_instants
#> [1] "2020-05-17 12:05:03 UTC" "2020-06-16 12:05:03 UTC"
as_tod(my_instants)
#> [1] 12.08417 12.08417
as_tod(my_instants, unit.out = "tod_time")
#> [1] "12:05:03" "12:05:03"