The values are stored as a difftime vector with a custom class, and always with "seconds" as unit for robust coercion to numeric. Supports construction from time values, coercion to and from various data types, and formatting. Can be used as a regular column in a data frame.

hms(seconds = NULL, minutes = NULL, hours = NULL, days = NULL)


as.hms(x, ...)

# S3 method for default
as.hms(x, ...)

# S3 method for difftime
as.hms(x, ...)

# S3 method for numeric
as.hms(x, ...)

# S3 method for character
as.hms(x, ...)

# S3 method for POSIXt
as.hms(x, tz = pkgconfig::get_config("hms::default_tz", ""),

# S3 method for POSIXlt
as.hms(x, tz = pkgconfig::get_config("hms::default_tz", ""),

# S3 method for hms
as.POSIXct(x, ...)

# S3 method for hms
as.POSIXlt(x, ...)

# S3 method for hms
as.character(x, ...)

# S3 method for hms, row.names = NULL, optional = FALSE, ...,
  nm = paste(deparse(substitute(x), width.cutoff = 500L), collapse = " "))

# S3 method for hms
format(x, ...)

# S3 method for hms
print(x, ...)


seconds, minutes, hours, days

Time since midnight. No bounds checking is performed.


An object.


Arguments passed on to further methods.


The time zone in which to interpret a POSIXt time for extracting the time of day. The default is now the zone of x but was "UTC" for v0.3 and earlier. The previous behavior can be restored by calling pkgconfig::set_config("hms::default_tz", "UTC"), see pkgconfig::set_config().


NULL or a character vector giving the row names for the data frame. Missing values are not allowed.


logical. If TRUE, setting row names and converting column names (to syntactic names: see make.names) is optional. Note that all of R's base package methods use optional only for column names treatment, basically with the meaning of data.frame(*, check.names = !optional).


Name of column in new data frame


For hms, all arguments must have the same length or be NULL. Odd combinations (e.g., passing only seconds and hours but not minutes) are rejected.


hms(56, 34, 12)
#> 12:34:56
#> hms()
#> 00:00:01
#> 12:34:56
#> 17:00:40.236540
#> [1] "1970-01-01 00:00:01 UTC"
data.frame(a = hms(1))
#> a #> 1 00:00:01
d <- data.frame(hours = 1:3) d$hours <- hms(hours = d$hours) d
#> hours #> 1 01:00:00 #> 2 02:00:00 #> 3 03:00:00