Skip to content

Instantly share code, notes, and snippets.

@dantonnoriega
Created July 24, 2019 23:13
Show Gist options
  • Save dantonnoriega/bb1a6f86fbaa1052c7c681273aca853c to your computer and use it in GitHub Desktop.
Save dantonnoriega/bb1a6f86fbaa1052c7c681273aca853c to your computer and use it in GitHub Desktop.
convert epoch time to days, minutes, hh, mm
# e.g. epoch_time = 1562791262
as.POSIXct(1562791262, origin = '1970-01-01', tz = 'GMT')
#> [1] "2019-07-10 20:41:02 GMT"
as.numeric(as.Date(as.POSIXct(1562791262, origin = '1970-01-01', tz = 'GMT')))
#> [1] 18087
day = (epoch_time) %/% (3600 * 24) # day since 1970-01-01
min = (epoch_time %% (3600 * 24)) %/% 60 # minute of the day
hh = (epoch_time %% (3600 * 24) / 60) %/% 60 # hour in HH
mm = ((epoch_time %% (3600 * 24)) / 60) %% 60 %/% 1 # the minute of the hour MM
(epoch_time) %/% (3600 * 24)
#> [1] 18087
(epoch_time %% (3600 * 24)) %/% 60
#> [1] 1241
(epoch_time %% (3600 * 24) / 60) %/% 60
#> [1] 20
((epoch_time %% (3600 * 24)) / 60) %% 60 %/% 1
#> [1] 41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment