Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #format #date
ADD COMMENT
Topic
Name
9+1 =