Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seconds since midnight to time of day

Tags:

time

r

lubridate

There is a post that shows how use lubridate to go from time to seconds since midnight. How about going from seconds since midnight to time of day?

So, instead of using 06:52:32 to get 24752.05, how do I use 24752.05 to get 06:52:32?

like image 840
user1895691 Avatar asked Jan 16 '13 22:01

user1895691


People also ask

How many seconds into the day are we?

There are 24 hrs in a day. So there are 2460 mins in a day. ( 1hr=60 mins) So there are 246060 seconds in a day. (1 min = 60 seconds) Therefore 86,400 seconds in a day.

How do you find the time of day in seconds in Python?

Get Current Time in PythonUse the time. time() function to get the current time in seconds since the epoch as a floating-point number. This method returns the current timestamp in a floating-point number that represents the number of seconds since Jan 1, 1970, 00:00:00. It returns the current time in seconds.

How is epoch time calculated?

What is epoch time? The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).


1 Answers

Use as.POSIXct() on the sum of the midnight timestamp and your offset, possibly adjusting by setting TZ.

In my default time zone:

R> as.POSIXct(trunc(Sys.time(), units="days") + 24752.05)
[1] "2013-01-16 06:52:32.04 CST"
R> 

Note that the answer (just like the preceding question) can be solved just fine in base R, persistent rumors that every time question has to involve lubridate not withstanding.

like image 120
Dirk Eddelbuettel Avatar answered Nov 04 '22 07:11

Dirk Eddelbuettel