period_to_seconds

0th

Percentile

Contrive a period to/from a given number of seconds

period_to_seconds() approximately converts a period to seconds assuming there are 365.25 days in a calendar year and 365.25/12 days in a month.

seconds_to_period() create a period that has the maximum number of non-zero elements (days, hours, minutes, seconds). This computation is exact because it doesn't involve years or months.

Usage
period_to_seconds(x)

seconds_to_period(x)

Arguments
x

A numeric object. The number of seconds to coerce into a period.

Value

A number (period) that roughly equates to the period (seconds) given.

Aliases
  • period_to_seconds
  • seconds_to_period
Documentation reproduced from package lubridate, version 1.7.4, License: GPL (>= 2)

Community examples

ranklord@gmail.com at Apr 16, 2017 lubridate v1.6.0

**Basic samples** ``` library(lubridate) seconds_to_period(86400) ``` [1] "1d 0H 0M 0S" `seconds_to_period(48000)` [1] "13H 20M 0S" **If you need to format** ``` td <- seconds_to_period(86400) sprintf('%02d %02d:%02d:%02d', day(td), td@hour, minute(td), second(td)) ``` [1] "01 00:00:00" **If it spans for > 99 days** ``` td <- seconds_to_period(1e7) sprintf('%03d %02d:%02d:%02d', day(td), td@hour, minute(td), second(td)) ``` [1] "115 17:46:40"