javascript get date today code example
Example 1: return current date in javascript
let today = new Date().toLocaleDateString()
console.log(today)
Example 2: how to get today date in javascript
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 3: get today's date javascript
var today = new Date();
Example 4: javascript date methods
var d= new Date();
d.getFullYear();
d.getMonth();
d.getDate();
d.getHours();
d.getMinutes();
d.getSeconds();
d.getMilliseconds();
d.getTime();
Example 5: current date in javascript
const localDate = new Date();
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const days = [
"Sunday",
"Monday ",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
const currentDay = days[localDate.getDay()];
const currentDate = localDate.getDate();
const currentMonth = months[localDate.getMonth()];
const currentYear = localDate.getFullYear();
console.log(`${currentDay}, ${currentDate} ${currentMonth}, ${currentYear}`);
Example 6: get today's date in js
var utc = new Date().toJSON().slice(0,10).replace(/-/g,'/');
document.write(utc);