Convert date with any format into DD/MM/YYYY format

To convert a date with any format into DD/MM/YYYY format using the Moment.js library in JavaScript, you can follow these steps:

Use Moment.js to parse and format the date:

<!DOCTYPE html>

<html lang=”en”>

<head>

 <meta charset=”UTF-8″>

 <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>

 <title>Date Format Example</title>

 <script src=”https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js”></script>

</head>

<body>

<script>

 // Your date string with any format

 var dateString = “2023-12-31”; // Replace this with your date string

 // Parse and format the date using Moment.js

 var formattedDate = moment(dateString).format(“DD/MM/YYYY”);

 // Display the formatted date

 console.log(“Formatted Date:”, formattedDate);

</script>

</body>

</html>

Leave a comment

Your email address will not be published. Required fields are marked *