-
-
Save scsskid/41769ef9eb5149b4ed9302d48c432924 to your computer and use it in GitHub Desktop.
JavaScript Date Object CheatSheet | #date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Date Object CheatSheet | |
| // The Date object is used to work with dates and times. | |
| // More: http://www.w3schools.com/jsref/jsref_obj_date.asp | |
| // 1. Instantiating a Date. | |
| var date = new Date(); | |
| var date = new Date(milliseconds); | |
| var date = new Date(dateString); | |
| var date = new Date(year, month, day, hours, minutes, seconds, milliseconds); | |
| // 2. Date Object Properties. | |
| date.constructor; // Returns the function that created the Date object's prototype. | |
| date.prototype; // Allows you to add properties and methods to an object. | |
| // 3. Date Object Methods. | |
| date.getDate(); // Returns the day of the month (from 1-31). | |
| date.getDay(); // Returns the day of the week (from 0-6). | |
| date.getFullYear(); // Returns the year (four digits). | |
| date.getHours(); // Returns the hour (from 0-23). | |
| date.getMilliseconds(); // Returns the milliseconds (from 0-999). | |
| date.getMinutes(); // Returns the minutes (from 0-59). | |
| date.getMonth(); // Returns the month (from 0-11). | |
| date.getSeconds(); // Returns the seconds (from 0-59). | |
| date.getTime(); // Returns the number of milliseconds since midnight Jan 1, 1970. | |
| date.getTimezoneOffset(); // Returns the time difference between UTC time and local time, in minutes. | |
| date.getUTCDate(); // Returns the day of the month, according to universal time (from 1-31). | |
| date.getUTCDay(); // Returns the day of the week, according to universal time (from 0-6). | |
| date.getUTCFullYear(); // Returns the year, according to universal time (four digits). | |
| date.getUTCHours(); // Returns the hour, according to universal time (from 0-23). | |
| date.getUTCMilliseconds(); // Returns the milliseconds, according to universal time (from 0-999). | |
| date.getUTCMinutes(); // Returns the minutes, according to universal time (from 0-59). | |
| date.getUTCMonth(); // Returns the month, according to universal time (from 0-11). | |
| date.getUTCSeconds(); // Returns the seconds, according to universal time (from 0-59). | |
| date.parse(datestring); // Parses a date string and returns the number of milliseconds since midnight of January 1, 1970. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment