Skip to content

Instantly share code, notes, and snippets.

@scsskid
Forked from LeCoupa/date-object-cheatsheet.js
Last active September 1, 2021 15:34
Show Gist options
  • Save scsskid/41769ef9eb5149b4ed9302d48c432924 to your computer and use it in GitHub Desktop.
Save scsskid/41769ef9eb5149b4ed9302d48c432924 to your computer and use it in GitHub Desktop.

Revisions

  1. scsskid revised this gist Sep 1, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // src: https://github.com/LeCoupa/awesome-cheatsheets

    // Date Object CheatSheet
    // The Date object is used to work with dates and times.
    // More: http://www.w3schools.com/jsref/jsref_obj_date.asp
  2. scsskid revised this gist Nov 26, 2020. No changes.
  3. @LeCoupa LeCoupa revised this gist Nov 10, 2017. No changes.
  4. Julien Le Coupanec revised this gist Jul 3, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -71,8 +71,8 @@ date.toUTCString(); // Converts a Date object to a string, according to
    date.valueOf(); // Returns the primitive value of a Date object.


    // 3. Date Object Static Methods.
    // 4. Date Object Static Methods.


    date.parse(datestring); // Parses a date string and returns the number of milliseconds since midnight of January 1, 1970.
    date.UTC(year,month,day,hours,minutes,seconds,millisec); // Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time.
    Date.parse(datestring); // Parses a date string and returns the number of milliseconds since midnight of January 1, 1970.
    Date.UTC(year,month,day,hours,minutes,seconds,millisec); // Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time.
  5. Julien Le Coupanec revised this gist Jul 3, 2014. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -42,8 +42,6 @@ date.getUTCMinutes(); // Returns the minutes, according to universal time
    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.

    date.setDate(day); // Sets the day of the month of a date object.
    date.setFullYear(year, month, day); // Sets the year (four digits) of a date object.
    date.setHours(hour, min, sec, millisec); // Sets the hour of a date object.
    @@ -70,8 +68,11 @@ date.toLocaleString(); // Converts a Date object to a string, using locale
    date.toString(); // Converts a Date object to a string.
    date.toTimeString(); // Convert the time portion of a Date object to a string.
    date.toUTCString(); // Converts a Date object to a string, according to universal time.
    date.valueOf(); // Returns the primitive value of a Date object.

    date.UTC(year,month,day,hours,minutes,seconds,millisec); // Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time.
    date.valueOf(); // Returns the primitive value of a Date object.

    // 3. Date Object Static Methods.


    date.parse(datestring); // Parses a date string and returns the number of milliseconds since midnight of January 1, 1970.
    date.UTC(year,month,day,hours,minutes,seconds,millisec); // Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time.
  6. Julien Le Coupanec revised this gist Jul 3, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -71,7 +71,7 @@ date.toString(); // Converts a Date object to a string.
    date.toTimeString(); // Convert the time portion of a Date object to a string.
    date.toUTCString(); // Converts a Date object to a string, according to universal time.

    Date.UTC(year,month,day,hours,minutes,seconds,millisec); // Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time.
    Date.valueOf(); // Returns the primitive value of a Date object.
    date.UTC(year,month,day,hours,minutes,seconds,millisec); // Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time.
    date.valueOf(); // Returns the primitive value of a Date object.


  7. Julien Le Coupanec revised this gist Jul 3, 2014. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -61,4 +61,17 @@ date.setUTCMinutes(min, sec, millisec); // Set the minutes of a date object
    date.setUTCMonth(month, day); // Sets the month of a date object, according to universal time.
    date.setUTCSeconds(sec, millisec); // Set the seconds of a date object, according to universal time.

    date.toDateString(); // Converts the date portion of a Date object into a readable string.
    date.toISOString(); // Returns the date as a string, using the ISO standard.
    date.toJSON(); // Returns the date as a string, formatted as a JSON date.
    date.toLocaleDateString(); // Returns the date portion of a Date object as a string, using locale conventions.
    date.toLocaleTimeString(); // Returns the time portion of a Date object as a string, using locale conventions.
    date.toLocaleString(); // Converts a Date object to a string, using locale conventions.
    date.toString(); // Converts a Date object to a string.
    date.toTimeString(); // Convert the time portion of a Date object to a string.
    date.toUTCString(); // Converts a Date object to a string, according to universal time.

    Date.UTC(year,month,day,hours,minutes,seconds,millisec); // Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time.
    Date.valueOf(); // Returns the primitive value of a Date object.


  8. Julien Le Coupanec revised this gist Jul 3, 2014. 1 changed file with 17 additions and 10 deletions.
    27 changes: 17 additions & 10 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -44,14 +44,21 @@ date.getUTCSeconds(); // Returns the seconds, according to universal time

    date.parse(datestring); // Parses a date string and returns the number of milliseconds since midnight of January 1, 1970.

    date.setDate(day); // Sets the day of the month of a date object.
    date.setFullYear(year, month, day); // Sets the year (four digits) of a date object.
    date.setHours(hour, min, sec, millisec); // Sets the hour of a date object.
    date.setMilliseconds(millisec); // Sets the milliseconds of a date object.
    date.setMinutes(min, sec, millisec); // Set the minutes of a date object.
    date.setMonth(month, day); // Sets the month of a date object.
    date.setSeconds(sec, millisec); // Sets the seconds of a date object.
    date.setTime(millisec); // Sets a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970.

    date.
    date.setDate(day); // Sets the day of the month of a date object.
    date.setFullYear(year, month, day); // Sets the year (four digits) of a date object.
    date.setHours(hour, min, sec, millisec); // Sets the hour of a date object.
    date.setMilliseconds(millisec); // Sets the milliseconds of a date object.
    date.setMinutes(min, sec, millisec); // Set the minutes of a date object.
    date.setMonth(month, day); // Sets the month of a date object.
    date.setSeconds(sec, millisec); // Sets the seconds of a date object.
    date.setTime(millisec); // Sets a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970.

    date.setUTCDate(day); // Sets the day of the month of a date object, according to universal time.
    date.setUTCFullYear(year, month, day); // Sets the year of a date object, according to universal time (four digits).
    date.setUTCHours(hour, min, sec, millisec); // Sets the hour of a date object, according to universal time.
    date.setUTCMilliseconds(millisec); // Sets the milliseconds of a date object, according to universal time.
    date.setUTCMinutes(min, sec, millisec); // Set the minutes of a date object, according to universal time.
    date.setUTCMonth(month, day); // Sets the month of a date object, according to universal time.
    date.setUTCSeconds(sec, millisec); // Set the seconds of a date object, according to universal time.


  9. Julien Le Coupanec revised this gist Jul 3, 2014. 1 changed file with 10 additions and 7 deletions.
    17 changes: 10 additions & 7 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -44,11 +44,14 @@ date.getUTCSeconds(); // Returns the seconds, according to universal time

    date.parse(datestring); // Parses a date string and returns the number of milliseconds since midnight of January 1, 1970.








    date.setDate(day); // Sets the day of the month of a date object.
    date.setFullYear(year, month, day); // Sets the year (four digits) of a date object.
    date.setHours(hour, min, sec, millisec); // Sets the hour of a date object.
    date.setMilliseconds(millisec); // Sets the milliseconds of a date object.
    date.setMinutes(min, sec, millisec); // Set the minutes of a date object.
    date.setMonth(month, day); // Sets the month of a date object.
    date.setSeconds(sec, millisec); // Sets the seconds of a date object.
    date.setTime(millisec); // Sets a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970.

    date.

  10. Julien Le Coupanec revised this gist Jul 3, 2014. 1 changed file with 24 additions and 3 deletions.
    27 changes: 24 additions & 3 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // Date Object CheatSheet
    // The Date object is used to work with dates and times.
    // More: http://www.tutorialspoint.com/javascript/javascript_date_object.htm
    // More: http://www.w3schools.com/jsref/jsref_obj_date.asp


    // 1. Instantiating a Date.
    @@ -22,8 +22,29 @@ 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.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.





  11. Julien Le Coupanec created this gist Jul 3, 2014.
    33 changes: 33 additions & 0 deletions date-object-cheatsheet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    // Date Object CheatSheet
    // The Date object is used to work with dates and times.
    // More: http://www.tutorialspoint.com/javascript/javascript_date_object.htm


    // 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).