Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Understanding particular date/time format

What is the use of the following format, supported by Moment.js?

> const moment=require('moment')
undefined
> moment().format('h AM/PM')
'3 PM10/P10'

Particularly, what does PM10/P10 mean? From the docs here.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s parsing the string through its constituent pieces of the date time spec: https://en.wikipedia.org/wiki/ISO_8601

However the wiki it’s tricky to understand, so to breakdown what its returning:

The string h AM/PM breakdown as:

  • h (no zero) Hour
  • A AM / PM postfix
  • M Month
  • /P a text slash and letter P
  • M Month

Therefore splitting on the output string: 3 PM10/P10 looks like this:

h A  M  /P M
3 PM 10 /P 10

That said, you probably only want the h A as your format string – this cheat-sheet should help: https://devhints.io/moment

> const moment=require('moment')
undefined
> moment().format('h A')
'3 PM'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading