javascript current date format yyyy-mm-dd hh mm ss 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');
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
document.write(today);
Example 2: javascript convert date to yyyy-mm-dd
const formatYmd = date => date.toISOString().slice(0, 10);
formatYmd(new Date());
Example 3: javascript date format dd-mm-yyyy
var date_format = new Date();
document.write(innerHTML = date_format.getMonth()+'-'+ date_format.getDate()+'-'+date_format.getFullYear());
Example 4: javascript get current date format dd mm yyyy hh mm ss
dformat = [d.getDate(), d.getMonth() + 1, d.getFullYear()].join('/') + ' ' + [d.getHours(),d.getMinutes(),d.getSeconds()].join(':');
Example 5: javascript format date mm/dd/yyyy
function pad2(n) {
return (n < 10 ? '0' : '') + n;
}
var date = new Date();
var month = pad2(date.getMonth()+1);
var day = pad2(date.getDate());
var year= date.getFullYear();
var formattedDate = month+"/"+day+"/"+year;
alert(formattedDate);