xxxxxxxxxx
// Get current date
const currentDate = new Date();
// Format the date as per requirement
const options = { year: 'numeric', month: 'long', day: 'numeric' };
const formattedDate = currentDate.toLocaleDateString(undefined, options);
console.log(formattedDate);
xxxxxxxxxx
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
xxxxxxxxxx
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
console.log(date)
// output 2021-7-9
xxxxxxxxxx
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
const currentDate = `${year}-${month}-${day}`;
console.log(currentDate);
xxxxxxxxxx
let today = new Date().toISOString().slice(0, 10)
console.log(today)
xxxxxxxxxx
let today = new Date();
let month = today.getMonth() + 1;
month = month < 10 ? "0" + month : month;
let days = today.getDate() < 10 ? "0" + today.getDate() : today.getDate();
today = today.getFullYear() + "-" + month + "-" + days;
console.log(today);
xxxxxxxxxx
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);
xxxxxxxxxx
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);
xxxxxxxxxx
// Creating a new Date object
let today = new Date();
// Extracting the year, month, and day
let year = today.getFullYear();
let month = today.getMonth() + 1; // Month starts from 0
let day = today.getDate();
// Formatting the date in desired format (e.g., DD-MM-YYYY)
let formattedDate = `${day}-${month}-${year}`;
// Printing the formatted date
console.log(formattedDate);