xxxxxxxxxx
var date = new Date(); //Will use computers date by default.
//parameters will specify date you put to input
var date = new Date(year, month, day, hours, minutes, seconds, milliseconds);
xxxxxxxxxx
var d= new Date();
d.getFullYear();//Get the year as a four digit number (yyyy)
d.getMonth();//Get the month as a number (0-11)
d.getDate();//Get the day as a number (1-31)
d.getHours();//Get the hour (0-23)
d.getMinutes();//Get the minute (0-59)
d.getSeconds();//Get the second (0-59)
d.getMilliseconds();//Get the millisecond (0-999)
d.getTime();//Get the time (milliseconds since January 1, 1970)
xxxxxxxxxx
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
}
xxxxxxxxxx
var d= new Date();
d.getFullYear();//Get the year as a four digit number (yyyy)
d.getMonth();//Get the month as a number (0-11)
d.getDate();//Get the day as a number (1-31)
d.getHours();//Get the hour (0-23)
d.getMinutes();//Get the minute (0-59)
d.getSeconds();//Get the second (0-59)
d.getMilliseconds();//Get the millisecond (0-999)
d.getTime();//Get the time (milliseconds since January 1, 1970)
xxxxxxxxxx
var currentDate = new Date();
var dateFromTimeStamp= new Date(1560807962);
var dateFromString = new Date('December 17, 1995 03:24:00');
//new Date(year, month, day, hours, minutes, seconds, milliseconds)
//0= Jan, 11=Dec
var dateFromYearMonthDay = new Date(2018, 11, 26, 0, 0, 0, 0);
xxxxxxxxxx
var dateWithTime = new Date().toLocaleString().replace(",", "")
console.log(dateWithTime)
//output :6/24/2022 9:36:33 PM
xxxxxxxxxx
// Get the current date and time
const currentDate = new Date();
// Get the current year, month, and day
const year = currentDate.getFullYear();
const month = currentDate.getMonth() + 1; // Months are zero-based, so add 1
const day = currentDate.getDate();
// Get the current hour, minute, and second
const hour = currentDate.getHours();
const minute = currentDate.getMinutes();
const second = currentDate.getSeconds();
// Display the date and time
console.log(`Current date and time: ${year}-${month}-${day} ${hour}:${minute}:${second}`);
xxxxxxxxxx
const today = new Date()
const birthday = new Date('December 17, 1995 03:24:00') // DISCOURAGED: may not work in all runtimes
const birthday2 = new Date('1995-12-17T03:24:00') // This is ISO8601-compliant and will work reliably
const birthday3 = new Date(1995, 11, 17) // the month is 0-indexed
const birthday4 = new Date(1995, 11, 17, 3, 24, 0)
const birthday5 = new Date(628021800000) // passing epoch timestamp
xxxxxxxxxx
const today = new Date();
const yyyy = today.getFullYear();
let mm = today.getMonth() + 1; // Months start at 0!
let dd = today.getDate();
if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;
const formattedToday = dd + '/' + mm + '/' + yyyy;
document.getElementById('DATE').value = formattedToday;
xxxxxxxxxx
var d = new Date();
//1628202691394 miliseconds passed since 1970
Number(d)
Date("2017-06-23"); // date declaration
Date("2017"); // is set to Jan 01
Date("2017-06-23T12:00:00-09:45"); // date - time YYYY-MM-DDTHH:MM:SSZ
Date("June 23 2017"); // long date format
Date("Jun 23 2017 07:45:00 GMT+0100 (Tokyo Time)"); // time zone