Dates In Javascript
DATE
- new Date(); //current date and time:
- new Date(year, month, day, hours, minutes, seconds, milliseconds);//specified date and time. & at least two parameters used
- new Date(milliseconds); //from 01/01/1970 00:00:00 to millisecons
- new Date(date string); //ie var d = new Date("October 13, 2014 11:13:00");
- var d = new Date(); //Sat, 21 Dec 2019 16:21:36
document.getElementById("demo").innerHTML = d.toUTCString(); //to UTC (CORDINATE UNIVERSAL TIME) Sat, 21 Dec 2019 16:21:36 GMT
d.toDateString(); //Sat Dec 21 2019
FORMATES:
var d = new Date("2015-03-25"); //
var d = new Date("2015"); //
GET METHODS:
var d = new Date();
document.getElementById("demo").innerHTML = d.getTime();
- d.getFullYear();
- d.getMonth();
- d.getDate();
- d.getHours();
- d.getMinutes();
- d.getSeconds();
- d.getMilliseconds();
- d.getDay();
SET METHODS:
- d.setFullYear(2020);
- setDate() Set the day as a number (1-31)
- setFullYear() Set the year (optionally month and day)
- setHours() Set the hour (0-23)
- setMilliseconds() Set the milliseconds (0-999)
- setMinutes() Set the minutes (0-59)
- setMonth() Set the month (0-11)
- setSeconds() Set the seconds (0-59)
- setTime() Set the time (milliseconds since January 1, 1970)
JavaScript counts months from 0 to 11.