I have a string with 12
hour formatted time only
var time="12:10:12: PM"
I want to convert this string to seconds.
how can i do this in moment.js
?
To convert hh:mm:ss to seconds:Convert the hours to seconds, by multiplying by 60 twice. Convert the minutes to seconds by multiplying by 60 .
Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.
MomentJS is a JavaScript library which helps is parsing, validating, manipulating and displaying date/time in JavaScript in a very easy way. This chapter will provide an overview of MomentJS and discusses its features in detail. Moment JS allows displaying of date as per localization and in human readable format.
Try something like this:
moment('12:10:12: PM', 'HH:mm:ss: A').diff(moment().startOf('day'), 'seconds');
returns 43812
I was just trying to achieve the same thing. using https://momentjs.com/
This is how I got what I wanted (03:11:23 => 11483 seconds)
myVar = moment.duration(myVar).asSeconds()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With