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);
let today = new Date().toLocaleDateString();
//or function
function getDate()
{
let today = new Date();
let dd = String(today.getDate()).padStart(2, '0');
let mm = String(today.getMonth() + 1).padStart(2, '0'); //janvier = 0
let yyyy = today.getFullYear();
return `${yyyy}-${mm}-${dd}`;
//return dd + '/' + mm + '/' + yyyy; // change form if you need
}
var dateString = "23/10/2015"; // Oct 23
var dateParts = dateString.split("/");
// month is 0-based, that's why we need dataParts[1] - 1
var dateObject = new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]);
console.log(dateObject); // Fri Oct 23 2015 00:00:00
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
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
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 = year+"-"+month+"-"+day;
alert(formattedDate); //2021-02-28
var dateString = "20120515";
var year = dateString.substring(0,4);
var month = dateString.substring(4,6);
var day = dateString.substring(6,8);
var date = new Date(year, month-1, day);
javascript yyyy-mm-dd to mm-dd-yyyy human readable format
function formatDate(DB_date){
// Get Date from DB then format it to be human readable
// DB_date comes in as yyyy-mm-dd which throws off the date format by one day
var ymdSplit = DB_date.split('-');
// so we split it into an array and then we can use the array to create a new date object
// console.log(ymdSplit[0])
// console.log(ymdSplit[1])
// console.log(ymdSplit[2])
var d = new Date(""+ymdSplit[1]+"/"+ymdSplit[2]+"/"+ymdSplit[0]+"");
// re-assembles the date object into a string
// console.log(d)
var wd = d.getDay();
var mo = d.getMonth();
let weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
let months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
// console.log(weekdays[wd])
// console.log(months[mo])
// return this function so it comes back as: Tuesday, March 15th, 2022 :) all done!
return weekdays[wd] + ", " + months[mo] + " " + ymdSplit[2] + ", " + ymdSplit[0];
}