convert date in mm dd yyyy FROM date parse in javascript code example

Example 1: javascript format date to dd-mm-yyyy

function pad2(n) {
  return (n < 10 ? '0' : '') + n;
}

var date = new Date();
var month = pad2(date.getMonth()+1);//months (0-11)
var day = pad2(date.getDate());//day (1-31)
var year= date.getFullYear();

var formattedDate =  day+"-"+month+"-"+year;
alert(formattedDate); //28-02-2021

Example 2: convert date dd/mm/yyyy to date object js

DateParts = data.split("/");

new Date(+DateParts[2], DateParts[1] - 1, +DateParts[0]).setUTCHours(
      0,
      0,
      0,
      0
    )

Tags:

Php Example