Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract time from datetime using moment.js

my datetime format is given below.

var datetime =Wed Apr 8 15:05:00 UTC+0530 2015;

I only want to get the time 15.05

like image 741
Ramesh Rajendran Avatar asked Apr 08 '15 06:04

Ramesh Rajendran


People also ask

How can I get time from datetime in moment?

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

How do you find time from moment?

You can directly call function momentInstance. valueOf(), it will return numeric value of time similar to date. getTime() in native java script.

How can I remove time from date with MomentJS?

We can remove the time portion from a date with the startOf method. We pass in a date with the hour and minutes set into the moment function. Then we call startOf with the 'day' argument to get return a moment object with the time set to midnight of the same date.

How do you get time in 24 hour format?

Try: moment({ // Options here }). format('HHmm') . That should give you the time in a 24 hour format.


1 Answers

Use format() and specify the desired token.

moment().format('HH.mm').

Docs for tokens can be found here

like image 58
Swaraj Giri Avatar answered Sep 19 '22 02:09

Swaraj Giri