1

I want to format my data-string and sent it to the API like - DD/MM/YYY HH:MM AM/PM . How can it be done using momentjs . Please help

thelonelyCoder
  • 322
  • 4
  • 18

4 Answers4

3

From the moment docs: https://momentjs.com/docs/#/displaying/ , You could use the following formatting options for your output

console.log(moment().format("DD/MM/YYYY hh:mm a"));// for current moment
let customDate = "28/03/2020 12:34:56";
console.log(moment(customDate, "DD/MM/YYYY hh:mm:ss").format("DD/MM/YYYY hh:mm a"));
<script src="https://momentjs.com/downloads/moment.js"></script>
joy08
  • 9,004
  • 8
  • 38
  • 73
0

It seems you are new to the community . But please keep in mind you should show what you have done so far to get help .You can do something like this.

const today = moment();
console.log(
  "Today's date is: " + 
  today.format('DD/MM/YYYY HH:MM A')
);
Harmandeep Singh Kalsi
  • 3,315
  • 2
  • 14
  • 26
0

You can do like this:

moment('24/12/2019 09:15:00', "DD/MM/YYYY HH:mm A");

You should look on moment.js documentation before you try to get help.

Hashemi Rafsan
  • 301
  • 1
  • 5
  • 14
0

You can use moment().format("DD/MM/YYYY kk:mm A")

For all the formats please check - https://momentjs.com/docs/#/displaying/

Sudhansu Bhatta
  • 101
  • 1
  • 6