How to Convert Mm:Ss.00 to Seconds.00

How to convert an H:MM:SS time string to seconds in Python?

def get_sec(time_str):
"""Get seconds from time."""
h, m, s = time_str.split(':')
return int(h) * 3600 + int(m) * 60 + int(s)

print(get_sec('1:23:45'))
print(get_sec('0:04:15'))
print(get_sec('0:00:25'))

Convert a duration %H:%M:%S to seconds

After we convert it to POSIXlt, extract the hour, min and sec and do the arithmetic

v1 <- strptime(durations, format='%H:%M:%S')
v1$hour * 3600 + v1$min * 60 + v1$sec
#[1] 3661

Or

c(unlist(unclass(v1)[c("hour", "min", "sec")]) %*% c(3600, 60, 1))

How to Convert time in minutes:seconds format to just seconds?

Here is an option with period_to_seconds after converting the Time column to Period class with ms. Then, we multiply the 'Seconds' and 'Period' to create the 'TimePassed'

library(lubridate)
df1$Seconds <- period_to_seconds(ms(df1$Time))
df1$TimePassed <- df1$Seconds * df1$Period

-output

df1
# Time Period Seconds TimePassed
#1 6:21 1 381 381
#2 8:52 2 532 1064
#3 15:00 2 900 1800

data

df1 <- structure(list(Time = c("6:21", "8:52", "15:00"), Period = c(1L, 
2L, 2L)), class = "data.frame", row.names = c(NA, -3L))

Convert HH:MM:SS string to seconds only in javascript

Try this:

var hms = '02:04:33';   // your input string
var a = hms.split(':'); // split it at the colons

// minutes are worth 60 seconds. Hours are worth 60 minutes.
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);

console.log(seconds);

Parsing seconds from mm.ss.00 string

Please try:

=RIGHT(A1,LEN(A1)-FIND(".",A1))+60*LEFT(A1,FIND(".",A1))  

This treats the likes of 1.44.72 as a string and manipulates it to strip off the numeric characters up to and including the first full stop (period in USA). The part including and after the plus sign may not be required if the minutes are to be ignored as it takes the number before the first full stop (minutes) converts to seconds and adds that to the seconds and hundredths of seconds from the first part of the formula.

The addition process converts the text result from string manipulation into a numeric format, though this could be achieved for seconds and hundredths of seconds in other ways.



Related Topics



Leave a reply



Submit