Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get hours, minutes, seconds from Moment.js object

I wonder if it is possible to fetch hours, minutes and seconds from Moment object?

for example:

Moment('12:16','HH:mm').get('minutes') //should result in '16'

I can't find anything like that in documentation though...

like image 909
janlan Avatar asked Nov 18 '19 10:11

janlan


2 Answers

Please try the following:-

Moment('12:16','HH:mm').minutes();

UPDATE:

Second option here - use format('mm'). It will return '16' in a string format.

Moment.js has documented minutes() function in link.

P.S. A piece of advice for the future - be more detailed in your question. Probably, you have some use-case in your code that you want to solve. In case if people have a description of your case they could help you to solve you case maybe in a more elegant way.

Have a nice day! Be kind and mark the answer that was useful for you as the right one!

like image 63
Shivratna Kumar Avatar answered Sep 24 '22 19:09

Shivratna Kumar


moment().minute(); // Number
moment().seconds(); // Number

Document : https://momentjs.com/docs/#/get-set/minute/

var now = moment().minutes();
alert(now);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
like image 31
Avid Programmer Avatar answered Sep 22 '22 19:09

Avid Programmer