Behind the Framework

Reduce Complexities & Improve Performance

Javascript Date Object

Lets take a MOMENT to learn the native Javascript Date object. The Date() constructor can be called with two or more arguments, in which case they are interpreted as the year, month, day, hour, minute, second, and millisecond, respectively, in local time. Date.UTC() works similarly, but it interprets the components as UTC time and also accepts a single argument representing the year. The example below demonstrates how you can perform operations with the date object and examples on how to format it.

There are many ways to format a date as a string. The JavaScript specification only specifies one format to be universally supported: the date time string format, a simplification of the ISO 8601 calendar date extended format.

  1. YYYY is the year, with four digits (0000 to 9999), or as an expanded year of + or - followed by six digits. The sign is required for expanded years. -000000 is explicitly disallowed as a valid year.
  2. MM is the month, with two digits (01 to 12). Defaults to 01. DD is the day of the month, with two digits (01 to 31). Defaults to 01.
  3. T is a literal character, which indicates the beginning of the time part of the string. The T is required when specifying the time part.
  4. HH is the hour, with two digits (00 to 23). As a special case, 24:00:00 is allowed, and is interpreted as midnight at the beginning of the next day. Defaults to 00.
  5. mm is the minute, with two digits (00 to 59). Defaults to 00.
  6. ss is the second, with two digits (00 to 59). Defaults to 00.
  7. sss is the millisecond, with three digits (000 to 999). Defaults to 000.
  8. Z is the timezone offset, which can either be the literal character Z (indicating UTC), or + or - followed by HH:mm, the offset in hours and minutes from UTC.

Various components can be omitted, so the following are all valid:

Date-only form: YYYY, YYYY-MM, YYYY-MM-DD Date-time form: one of the above date-only forms, followed by T, followed by HH:mm, HH:mm:ss, or HH:mm:ss.sss. Each combination can be followed by a time zone offset.

For More on Dates see