Convert HH:MM:SS to seconds in momentjs

给你一囗甜甜゛ 提交于 2020-01-22 08:56:52

问题


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?


回答1:


Try something like this:

moment('12:10:12: PM', 'HH:mm:ss: A').diff(moment().startOf('day'), 'seconds');

returns 43812




回答2:


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()


来源:https://stackoverflow.com/questions/29745586/convert-hhmmss-to-seconds-in-momentjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!