HNSKD
HNSKD

Reputation: 1644

How to change a period element (from lubridate package) to time with format "%H:%M:%S"?

How could we change the period element "19H 43M 0S" to "19:43:00" (specifically "%H:%M:%S" format) in R?

Upvotes: 0

Views: 208

Answers (1)

akrun
akrun

Reputation: 887911

We can use sprintf with get the format

library(lubridate)
sprintf("%02d:%02d:%02d", hour(v1), minute(v1), second(v1))
#[1] "19:43:00"

data

v1 <- period("19hours 43minutes")

Upvotes: 1

Related Questions