Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the meridian (am / pm) with momentsjs and angularjs

I have a question about the library moments.js, I have an application in angularjs where I have six select elements for the year, month, day, hour, minutes, and am / pm format. I am using the following format moment to build m.format date ('YYYY-MM-DD hh: mm: ss a).

The code is as follows:

var m = moment([scope.val.year, scope.val.month, scope.val.date, scope.val.hour, scope.val.minute]); //build date 

model.$setViewValue(m.format('YYYY-MM-DD hh:mm:ss a'))

I get the data m.hour (), m.minute (), etc but there is a way to get the am / pm format, I have not found anything about it, something perhaps as m.meridian () => "am "or" pm ".

I would build the array passing as parameter if am or pm, and then also would get from any date if am or pm date.

like image 696
ojedawinder Avatar asked Sep 26 '15 22:09

ojedawinder


People also ask

How do you show AM PM with a moment?

console. log( moment('Mon 03-Jul-2017, 11:00 AM', 'ddd DD-MMM-YYYY, hh:mm A'). format('hh:mm A') ); console. log( moment('Mon 03-Jul-2017, 11:00 PM', 'ddd DD-MMM-YYYY, hh:mm A').

How do you set 24 hour format in moment?

let dt = moment(); dt. format(“HH:mm”) // 24 hour time.

What is Moment () in JavaScript?

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.


1 Answers

You could also do something like m.format('a')

like image 81
Alex Cory Avatar answered Oct 14 '22 09:10

Alex Cory