Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert HH:mm into Moment.js

So I have some time data such as follows:

10:45 PM 11:35 PM 12:06 AM 01:34 AM 

All of these times are in America/Los_Angeles and each time is guaranteed to be after 09:00 PM in today in that timezone. So that times which are past midnight take place tomorrow.

Is there an elegant way to convert these times from the current format into moment.js objects with the times pinned to the appropriate day.

like image 978
Richard Avatar asked Apr 25 '14 01:04

Richard


People also ask

How do you convert HH MM SS to seconds?

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 .

How do you convert moments to time?

Convert time If you are creating timestamps using built-in new Date() , you can also use it to create moment objects: const timestamp = new Date(); const momentTimestamp = moment(timestamp); If you want to create a moment object using current date and time, just call moment() without any arguments.

What is Moment () in JavaScript?

Moment JS allows displaying of date as per localization and in human readable format. You can use MomentJS inside a browser using the script method. It is also available with Node. js and can be installed using npm.

Is MomentJS deprecated?

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.


1 Answers

moment('09:00','h:mm a').format('h:mm a'); 
like image 180
José Farías Avatar answered Oct 05 '22 02:10

José Farías