How to change json date to mm/dd/yy using moment.js?

Member

by jasen , in category: Javascript , 7 months ago

How to change json date to mm/dd/yy using moment.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 7 months ago

@jasen 

You can use moment.js to format the JSON date to mm/dd/yyyy format by using the following code:

1
2
3
4
5
6
7
// assuming your JSON date is stored in a variable called jsonDate
var jsonDate = "2021-08-10T10:30:00";

// parse the JSON date using moment.js
var formattedDate = moment(jsonDate).format("MM/DD/YYYY");

console.log(formattedDate); // Output: 08/10/2021


This code snippet will convert the JSON date "2021-08-10T10:30:00" to the formatted date "08/10/2021".