Class Date


class Date
Extends the native Date class with additional functionality.

Many of the date arithmetics are based on the information from http://www.merlyn.demon.co.uk/frames-1.htm.

Authors:
Henrik Lindqvist <henrik.lindqvist@llamalab.com>
Version:
Defined in Date.js

Property Summary
static read number DAY
Milliseconds in a day.
static read number HOUR
Milliseconds in an hour.
static read number MINUTE
Milliseconds in a minute.
static read number SECOND
Milliseconds in a second.
static read number WEEK
Milliseconds in a week.

Function Summary
Clone this date, creating a new instance.
Create a new instance with only the date part from this date.
format(string p, l)
Format this date into a string.
number getDayOfWeek([ o])
Get the localized day of week.
number getDayOfYear()
Get the day of the year for this date.
number getDaysInMonth()
Get the maximum days in the month for this date.
number getDaysInYear()
Get the maximum days in the year for this date.
number getWeekOfMonth([ l])
Get the week of month for this date.
number getWeekOfYear([ l])
Get the week of year for this date.
number getWeeksInYear()
Get the maximum weeks in the year of this date.
static object i18n([string l])
Get the date localization data for a specific language.
static Date parse([string p], [ l])
Parse a date string.
setDay(number d)
Set the "raw" unlocalized weekday.
setDayOfWeek(number d, [ o])
Set the localized day of week.
setDayOfYear(number d)
Set the day in the year for this date.
Set the timezone offset for this date.
setWeekOfMonth(number w, [ l])
Set the week of month for this date.
setWeekOfYear(number w, [ l])
Set the week of year for this date.
Create a new instance with only the time part from this date.
static Date today()
New Date instance for todays date, with time at midnight.

Property Details

property static read number DAY

Milliseconds in a day.

property static read number HOUR

Milliseconds in an hour.

property static read number MINUTE

Milliseconds in a minute.

property static read number SECOND

Milliseconds in a second.

property static read number WEEK

Milliseconds in a week.

Function Details

function clone

Date clone()
Clone this date, creating a new instance.
Returns:
clone of this date.

function datePart

Date datePart()
Create a new instance with only the date part from this date.

The time for the new date will be midnight.

Returns:
the date at midnight.
See also:

function format

format(string p, l)
Format this date into a string.

For pattern syntax, see java.text.SimpleDateFormat.

Parameters:
p - the pattern string of format
l - the language (string) or locationzation data used
See also:

function getDayOfWeek

number getDayOfWeek([ o])
Get the localized day of week.
Parameters:
[o] - first day of week number, language string or localization object.
Returns:
the weekday (1-7).
See also:

function getDayOfYear

number getDayOfYear()
Get the day of the year for this date.
Returns:
the day of this year (1-366).
See also:

function getDaysInMonth

number getDaysInMonth()
Get the maximum days in the month for this date.
Returns:
the number of days in this month, 1-31.

function getDaysInYear

number getDaysInYear()
Get the maximum days in the year for this date.
Returns:
the number of days in this year (1-366).

function getWeekOfMonth

number getWeekOfMonth([ l])
Get the week of month for this date.
Parameters:
[l] - language string or localization object.
Returns:
the week number of this month (0-6).
See also:

function getWeekOfYear

number getWeekOfYear([ l])
Get the week of year for this date.
Parameters:
[l] - language string or localization object.
Returns:
the week number of this year, 1-53.
See also:

function getWeeksInYear

number getWeeksInYear()
Get the maximum weeks in the year of this date.
Returns:
the number of weeks in this year, 1-53.

function i18n

static object i18n([string l])
Get the date localization data for a specific language.

Standard localizations included:

A good source of localization data are http://www.unicode.org/cldr/.

Parameters:
[l] - language, or user-agent language if omitted.
Returns:
localization data

function parse

static Date parse([string p], [ l])
Parse a date string. This function replaces the built-in parse but reverts back to the original if p is omitted.

For pattern syntax, see java.text.SimpleDateFormat.

Parameters:
[p] - the pattern string of format.
[l] - the language (string) or locationzation data used.
Returns:
the parsed Date, or NaN on failure.
See also:

function setDay

setDay(number d)
Set the "raw" unlocalized weekday.
Parameters:
d - the weekday (0-6).
See also:
getDay (native)

function setDayOfWeek

setDayOfWeek(number d, [ o])
Set the localized day of week.
Parameters:
d - the weekday (1-7).
[o] - first day of week number, language string or localization object.
See also:

function setDayOfYear

setDayOfYear(number d)
Set the day in the year for this date.
Parameters:
d - the day of year (1-366).
See also:

function setTimezoneOffset

setTimezoneOffset(number o)
Set the timezone offset for this date.

This function only adjusts the date to the supplied offset, it doesn’t actually set the timezone.

Parameters:
o - offset in minutes.
See also:
getTimezoneOffset (native)

function setWeekOfMonth

setWeekOfMonth(number w, [ l])
Set the week of month for this date.
Parameters:
w - the week number of this month (1-6).
[l] - language string or localization object.
See also:

function setWeekOfYear

setWeekOfYear(number w, [ l])
Set the week of year for this date.
Parameters:
w - the week number in this year, 1-53.
[l] - language string or localization object.
See also:

function timePart

Date timePart()
Create a new instance with only the time part from this date.

The date will be the JavaScript epoc (1970-01-01).

Returns:
the time of this date.
See also:

function today

static Date today()
New Date instance for todays date, with time at midnight.
Returns:
todays date at midnight.
See also: