Most of the methods available for working with the Date type (object) are used for direct setting or retrieving specified parts of the date or time values and they are Date type specific.

These methods are:

  • getTime(); Returns the milliseconds representation of the date (same as valueOf()).
  • setTime(milliseconds); Sets the milliseconds representation of the date.
  • getFullYear(); Returns the four digit year.
  • getUTCFullYear(); Returns the four digit year in UTC format.
  • setFullYear(year); Sets the four digit year of the date.
  • setUTCFullYear(year); Sets the four digit year in UTC format.
  • getMonth(); Returns the month of the date (0 = January, 11 = December).
  • getUTCMonth(); Returns the month in UTC format (0 = January, 11 = December).
  • setMonth(month); Sets the month of the date (0 ... 11). If the number is larger then 11, the year also increases.
  • setUTCMonth(month); Sets the month of the date in UTC format (0 ... 11). If the number is larger then 11, the year also increases.
  • getDate(); Returns the day of the month (1 through 31).
  • getUTCDate(); Returns the day of the month in UTC format (1 through 31).
  • setDate(date); Sets the day of the month for the date. If the number is greater than maximum for that month, the month also increases.
  • setUTCDate(date); Sets the day of the month for the date in UTC format. If the number is greater than maximum for that month, the month also increases.
  • getDay(); Returns the day of the week (0 = Sunday, 6 = Saturday).
  • getUTCDay(); Returns the day of the week in UTC format (0 = Sunday, 6 = Saturday).
  • getHours(); Returns the hours of the day (0 ... 23).
  • getUTCHours(); Returns the hours of the day in UTC format (0 ... 23).
  • setHours(hours); Sets the hours of the day (0 - 23). Setting numbers larger than 23 may increase the day as well.
  • setUTCHours(hours); Sets the hours of the day in UTC format (0 - 23). Setting numbers larger than 23 may increase the day as well.
  • getMinutes(); Returns the minutes of the hour (0 ... 59).
  • getUTCMinutes(); Returns the minutes of the hour in UTC format (0 ... 59).
  • setMinutes(minutes); Sets the minutes of the hour (0 ... 59). If the number is larger then 59, the hour increases.
  • setUTCMinutes(minutes); Sets the minutes of the hour in UTC format (0 ... 59). If the number is larger then 59, the hour increases.
  • getSeconds(); Returns the seconds of the minute (0 ... 59).
  • getUTCSeconds(); Returns the seconds of the minute in UTC format (0 ... 59).
  • setSeconds(seconds); Sets the date's seconds (0 ... 59). If the number is larger than 59, the minute increases.
  • setUTCSeconds(seconds); Sets the date's seconds in UTC format (0 ... 59). If the number is larger than 59, the minute increases.
  • getMilliseconds(); Returns the current milliseconds.
  • getUTCMilliseconds(); Returns the current milliseconds in UTC format.
  • setMilliseconds(milliseconds); Sets the current date's milliseconds.
  • setUTCMilliseconds(milliseconds); Sets the current date's milliseconds in UTC format.
  • getTimezoneOffset(); Returns the number of minutes that the local time zone is offset with (5 hours = 300 minutes).

Example

Example with date and time conversion methods:

 

›› go to examples ››