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.
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 .
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.
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.
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.
moment('09:00','h:mm a').format('h:mm a');
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