Skip to content
Advertisement

How to generate momentjs format from custom time object

Context:

Hi, I am trying to generate a moment.js format from the given start time and end time.

JavaScript

Using the above endTime property I am trying to get time in the format below :

2021-02-04T09:00 pm i.e This format https://momentjs.com/docs/#/displaying/format/ – “YYYY-MM-DDThh:mm a”

using this piece of code

JavaScript

Where I am adding the current date and end time in a customized way using a string literal to generate the desired format.

Problem:

I am getting 9:00 am instead of 9:00 pm.

2021-02-04T09:00 am

Not sure where I’m doing wrong. Any suggestion would be helpful.

JavaScript
JavaScript

Advertisement

Answer

After consulting Momentjs Format, I would propose the following solution:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement