| Option |
Description |
Arguments |
Return Value |
| language |
An object that contain the language to be used in formatting
the output from the print function |
N/A |
N/A |
Example:
alert(new Date().language.days.short[1]); // will alert Mo (short for Monday)
|
| daysInMonth |
Returns the number of days in the month |
N/A |
Number of days |
Example:
alert(new Date(2007, 8, 1).daysInMonth()); // will alert 30 (30 days in Septembar)
|
| isLeapYear |
Check if the year is a leap year or not |
N/A |
Boolean; true if the year is leap, false otherwise. |
Example:
alert(new Date(2008,0,1).isLeapYear()); // will alert true
alert(new Date(2009,0,1).isLeapYear()); // will alert false |
| fromString |
Create a date object from a string |
str: see below |
A new date object |
str: the string variable for the date. If the date can't be parsed using Date.parse() a list of custom values are provided below.
All custom values are relative to the date object.
Possible values:
- Any string that can be parsed by Date.parse()
- Short dates can use either a "/", "\" or "-" date separator, but must follow the month/day/year format, for example "7/20/96".
month are 1 for January 12 for December
- Long dates of the form "July 10 1995" can be given with the year, month, and day in any order, and the year in 2-digit or 4-digit form. If you use the 2-digit form, the year must be greater than or equal to 70.
- Month and day names must have two or more characters. Two character names that are not unique are resolved as the last match. For example, "Ju" is resolved as July, not June.
- Handles all standard time zones, as well as Universal Coordinated Time (UTC) and Greenwich Mean Time (GMT).
- Colons separate hours, minutes, and seconds, although all need not be specified. "10:", "10:11", and "10:11:12" are all valid.
- If the 24-hour clock is used, it is an error to specify "PM" for times later than 12 noon. For example, "23:15 PM" is an error.
- A string containing an invalid date is an error. For example, a string containing two years or two months is an error.
- "yesterday" a day before relative to the date object
- "tomorrow" a day after relative to the date object
- "today+[n]" [n] is any number
add the [n] number of days to the date
- "today-[n]" [n] is any number
subtract the [n] number of days from the date
- "last month" a month before relative to the date object
- "next month" a month after relative to the date object
- "month+[n]" [n] is any number
add the [n] number of months to the date
- "month-[n]" [n] is any number
subtract the [n] number of days from the date
- "last year"
- "next year"
- "year+[n]"
- "year-[n]"
|
Example:
alert(new Date().fromString("yesterday")); // will alert yesterday's day |
| fromObject |
Create a date from an object |
date_obj: see below |
A new date object |
date_obj: is a javascript object (key and value object) and
should have the following attributes
- date: can be either a number or a string
if string, the following values are allowed
- "[1st | 2nd | 3rd | 4th | 5th | last] sunday" either the 1st, 2nd, or 3rd, etc... sunday of the month.
will return the date for the [nth] or last sunday of the month
- "[1st | 2nd | 3rd | 4th | 5th | last] monday" same as above but for monday
- "[1st | 2nd | 3rd | 4th | 5th | last] tuesday"
- "[1st | 2nd | 3rd | 4th | 5th | last] wednesday"
- "[1st | 2nd | 3rd | 4th | 5th | last] thursday"
- "[1st | 2nd | 3rd | 4th | 5th | last] friday"
- "[1st | 2nd | 3rd | 4th | 5th | last] saturday"
- month: a numerical value for the month
0 for January 11 for December
- year: a numerical value for the year (for digits format)
- hour: a numerical value for the hour
- minute: a numerical value for the minute
- second: a numerical value for the second
- millisecond: a numerical value for the millisecond
if any of the values above is not defined, the current date value will be used. |
Example:
alert(new Date(2007,8,1).fromObject({'date':'last friday'})); // will alert the date for Sep 28th 2007
alert(new Date(2007,8,1).fromObject({'date':'3rd Monday'})); // will alert the date for Sep 17th 2007 |
| print |
Returns a formatted date string similar to PHP date function.
Please visit http://us.php.net/manual/en/function.date.php for more details
on the possible values. The only exception is the Y and o will return the same value |
format: the format of the date.
lang: a language object if using a different language than the date object |
String of the formatted date |
| alert(new Date(2007,8,12).print("D, d M Y")); // will alert Wed, 12 Sep 2007
|
| getWeekInYear |
Returns the number of week in the year |
N/A |
Number of weeks |
Example:
alert(new Date(2007,8,12).getWeekInYear()); // will alert 36
|
| getDayInYear |
Returns the number of day in the year |
N/A |
Number of days |
Example:
alert(new Date(2007,8,12).getDayInYear()); // will alert 253
|
| getHourInYear |
~~~~~~~ |
N/A |
Number of hours |
| getMinuteInYear |
~~~~~~~ |
N/A |
Number of minutes |
| getSecondInYear |
~~~~~~~ |
N/A |
Number of seconds |
| getMillisecondInYear |
~~~~~~~ |
N/A |
Number of milliseconds |
| getWeekSince |
Returns the number of week since a given date |
date: a JavaScript Date |
Number of weeks |
Example:
alert(new Date(2007,8,12).getWeekSince(new Date(2006,2,14))); // will alert 78
|
| getDaySince |
Returns the number of day in the year |
date: a JavaScript Date |
Number of days |
Example:
alert(new Date(2007,8,12).getDaySince(new Date(2006,2,14))); // will alert 547
|
| getHourSince |
~~~~~~~ |
~~~~~~~ |
Number of hours |
| getMinuteSince |
~~~~~~~ |
~~~~~~~ |
Number of minutes |
| getSecondSince |
~~~~~~~ |
~~~~~~~ |
Number of seconds |
| getMillisecondSince |
~~~~~~~ |
~~~~~~~ |
Number of milliseconds |
| timeDifference |
Returns the time difference in milliseconds between the date and the arguments date |
date: a JavaScript Date |
Difference in milliseconds |
Example:
alert(new Date(2007,8,12).timeDifference(new Date(2006,2,14))); // will alert 47260800000
|
| toSwatchInternetTime |
Returns the number of beats as a string (including the @ sign)
This function assume the browser handles the time zone and day time saving.
For more details about the Swatch Internet Time, please visit http://www.swatch.com/internettime/ |
N/A |
beats |
Example:
alert(new Date(2007,8,12,8,52,0).toSwatchInternetTime()); // will alert @702 (based on timezone)
|
| fromSwatchInternetTime |
Returns a JavaScript Date object (approximate time) from the given bean.
This function assume the browser handles the time zone and day time saving.
For more details about the Swatch Internet Time, please visit http://www.swatch.com/internettime/ |
beat: Swatch Internet Time beat |
A new date object |
Example:
alert(new Date().fromSwatchInternetTime(354)); // will alert the time at 10:47:31 (based on timezone)
|