Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract time from moment js object

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?

like image 238
ove Avatar asked Jan 16 '15 07:01

ove


People also ask

How do you extract time from a moment?

The moment(). hour() Method is used to get the hours from the current time or to set the hours.

How do I get time from moment to datetime?

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.

How do I get Epoch time from my moment?

To get a Unix timestamp (the number of seconds since the epoch) from a Moment , use moment#unix .

What will Moment () return?

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.


1 Answers

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/

like image 125
Pochen Avatar answered Oct 02 '22 23:10

Pochen