Skip to content
Prev 334406 / 398506 Next

Minutes after midnight to time

Hi,
On Dec 13, 2013, at 4:34 PM, Trevor Davies <davies.trevor at gmail.com> wrote:

            
I'm not sure what you mean by doing it by hand, but do the following do the trick for you?

# convert seconds to hours
s2h <- function(x=670.93*60) {
   h <- floor(x/3600)
   m <- floor((x - h*3600)/60)
   s <- x - h*3600 - m*60
   sprintf("%0.2d:%0.2d:%6.3f", h, m, s)

}
# convert minutes to hours
m2h <- function(x=670.93) {
   h <- floor(x/60)
   m <- floor(x - h*60)
   s <- (x - h*60 - m) * 60
   sprintf("%0.2d:%0.2d:%6.3f", h, m, s)
}
[1] "11:10:55.800"
[1] "11:10:55.800"

Cheers,
Ben
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org