How do i extract the time using moment.js?
"2015-01-16T12:00:00"
It should return "12:00:00 pm". The string return will be passed to the timepicker control below.
http://jdewit.github.com/bootstrap-timepicker
Any idea?
The moment(). hour() Method is used to get the hours from the current time or to set the hours.
With the diff function, we can calculate the difference between two datetime objects. const moment = require('moment'); let d1 = moment('2018-06-12'); let d2 = moment('2018-06-28'); let days = d2. diff(d1, 'days'); console. log(`Difference in days: ${days}`); let hours = d2.
To get a Unix timestamp (the number of seconds since the epoch) from a Moment , use moment#unix .
Displaying Formatted Dates Moment. js helps display date with specified formats. moment() returns a date and format() converts the date string tokens and replaces them with specified format values, which are readable.
If you read the docs (http://momentjs.com/docs/#/displaying/) you can find this format:
moment("2015-01-16T12:00:00").format("hh:mm:ss a")
See JS Fiddle http://jsfiddle.net/Bjolja/6mn32xhu/
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