Home > Blockchain >  Understanding particular date/time format
Understanding particular date/time format

Time:10-08

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.

CodePudding user response:

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'
  • Related