Format Date In Javascript Dd/mm/yyyy Code Example


Example 1: javascript date today dd mm yyyy


var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();

today = mm + '/' + dd + '/' + yyyy;
document.write(today);

Example 2: javascript format date yyyy-mm-dd


let today = new Date()
today.toISOString().split('T')[0]

Example 3: 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 4: javascript date parse yyyy-mm-dd


var dateString = "10/23/2015"; // Oct 23

var dateObject = new Date(dateString);

document.body.innerHTML = dateObject.toString();

Example 5: javascript date format dd-mm-yyyy


var date_format = new Date();
document.write(innerHTML = date_format.getMonth()+'-'+ date_format.getDate()+'-'+date_format.getFullYear());

Example 6: javascript format date mm/dd/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 = month+"/"+day+"/"+year;
alert(formattedDate); //03/02/2021

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable