// Creating a Date object var dateObj = new Date(); console.log(dateObj);
By doing this, we create an object with the current date and time formed by weekday, month, day, year, hours, minutes, seconds, and timezone. Now that's friggin precise 😝.
|getDate()||Returns the day of the month (1 to 31)|
|getDay()||Returns the weekday (0 - Sunday to 6 -|
|getFullYear()||Returns the full year (YYYY)|
|getMonth()||Returns the month (0 to 11)|
|getHours()||Returns the hours (0 to 23)|
|getMinutes()||Return the minutes (0 to 59)|
|getSeconds()||Returns the seconds (0 to 59)|
|getMilliseconds()||Returns the milliseconds (0 to 999)|
|getTime()||Returns the number of milliseconds since the|
|Epoch(Jan 1st, 1970, 00:00:00)|
|setTime()||Creates a specific date from milliseconds|
|since the epoch.|
The Epoch is present in most programming languages. We can consider it the starting point of counting the time. This is useful to do calculations with date and time.
|1 year (365 days)||31,536,000,000|
var Obj = new Date(); Obj = Obj.getTime(); var hours = Obj / 3600000; console.log(Math.floor(hours));
We created date objects without passing any arguments, this is why they represented the current time but we can also use them with specific objects or better to say a specific number of objects.
|Numeric arguments||Time represents|
|One||milliseconds since the epoch|
|Two||years and month (months go from 0 to 11)|
|Three||years, month, and day|
|Four||years, month, day, and hours|
|Five||years, month, days, hours, minutes|
|Six||years, month, day, hours, minutes, and|
var Obj = new Date(2021,1,24); console.log( Obj );
We can also pass strings as an argument and in different formats
- ISO date: "2020-03-18" (YYYY-MM-DD)
- Short Date: "03/18/2020" (MM/DD/YYYY)
- Long Date: "Mar 18 2020" or "18 Mar 2020"
I hope you guys have learnt and saved it for later reference
and if you found my grammatical mistakes then don't forget to comment them 😂