Learn R Programming

elpatron (version 0.0.4)

hhmmss: HH:MM:SS conversion

Description

Convert between seconds and the more readable "HH:MM:SS" time format.

Usage

hms_to_sec(hms)
sec_to_hms(sec, digits = 1, strip_zeros = FALSE)

Arguments

hms
character string; a time in the form "HH:MM:SS" ("HH:" is optional).
sec
numeric; seconds values.
digits
numeric (scalar); number of decimal places to be used for the seconds value in the "hours:minutes:seconds" string.
strip_zeros
logical; remove leading zeros? E.g. "00:26:01" becomes "26:01".

Examples

Run this code
x <- c("00:21:05", "25:51", NA, "00:26:01.1", "01:05:02.0")
(x <- hms_to_sec(x))
(x <- sec_to_hms(x, strip_zeros = TRUE))

Run the code above in your browser using DataLab