javascript get today date code example
Example 1: return current date in javascript
let today = new Date().toLocaleDateString()
console.log(today)
Example 2: how to use current data in javascript
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
Example 3: javascript date get current date
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var dateTime = date+' '+time;
The dateTime variable contains result as:
2018-8-3
Example 4: js get current date
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 5: get today's date javascript
var today = new Date();
Example 6: how to print date like 10-may-2018 in javascript
date.toString('YYYY-MM-dd'); 'Tue Feb 10 2015 15:42:50'
var date = new Date('4-1-2015');
date.getDay();
date.getYear();
date.getFullYear();
date.getMonth();
date.getUTCDate();