Class M.Date
Extends
M.Object.
M.Date defines a prototype for creating, handling and computing dates. It is basically a wrapper
to JavaScripts own date object that provides more convenient functionalities.
Defined in: date.js.
Constructor Attributes | Constructor Name and Description |
---|---|
M.Date()
|
Field Attributes | Field Name and Description |
---|---|
The native JavaScript date object.
|
|
The type of this object.
|
Method Attributes | Method Name and Description |
---|---|
create(dateString)
This method returns a date for a given date string.
|
|
daysFromDate(days)
This method returns a date in the future or past, based on 'days' and a given date.
|
|
daysFromNow(days)
This method returns a date in the future or past, based on 'days'.
|
|
format(format, utc)
This method formats a given date object according to the passed 'format' property and
returns it as a String.
|
|
hoursFromDate(hours)
This method returns a date in the future or past, based on 'hours' and a given date.
|
|
hoursFromNow(hours)
This method returns a date in the future or past, based on 'hours'.
|
|
millisecondsFromDate(milliseconds)
This method returns a date in the future or past, based on 'milliseconds' and a given date.
|
|
millisecondsFromNow(milliseconds)
This method returns a date in the future or past, based on 'milliseconds'.
|
|
minutesFromDate(minutes)
This method returns a date in the future or past, based on 'minutes' and a given date.
|
|
minutesFromNow(minutes)
This method returns a date in the future or past, based on 'minutes'.
|
|
now()
Returns the current date, e.g.
|
|
secondsFromDate(seconds)
This method returns a date in the future or past, based on 'seconds' and a given date.
|
|
secondsFromNow(seconds)
This method returns a date in the future or past, based on 'seconds'.
|
|
timeBetween(date, returnType)
This method returns the time between two dates, based on the given returnType.
|
|
tomorrow()
This method returns the date, 24h in the future.
|
|
This method returns the date, 24h in the past.
|
Field Detail
{Object}
date
The native JavaScript date object.
{String}
type
The type of this object.
Method Detail
{M.Date}
create(dateString)
This method returns a date for a given date string. It is based on JS Date's parse
method.
The following formats are accepted (time and timezone are optional):
- 11/12/2010
- 11/12/2010 15:28:15
- 11/12/2010 13:28:15 GMT
- 11/12/2010 15:28:15 GMT+0200
- 12 November 2010
- 12 November 2010 15:28:15
- 12 November 2010 13:28:15 GMT
- 12 November 2010 15:28:15 GMT+0200
- 12 Nov 2010
- 12 Nov 2010 15:28:15
- 12 Nov 2010 13:28:15 GMT
- 12 Nov 2010 15:28:15 GMT+0200
If a wrong formatted date string is given, the method will return null. Otherwise a
JS Date object will be returned.
- Parameters:
- {String} dateString
- The date string specifying a certain date.
- Returns:
- {M.Date} The date, specified by the given date string.
{M.Date}
daysFromDate(days)
This method returns a date in the future or past, based on 'days' and a given date. Basically
it adds or subtracts x days, but also checks for clock changes and automatically includes
these into the calculation of the future or past date.
- Parameters:
- {Number} days
- The number of days to be added to or subtracted from the current date.
- Returns:
- {M.Date} The date, x days in the future (based on parameter 'days').
{M.Date}
daysFromNow(days)
This method returns a date in the future or past, based on 'days'. Basically it adds or
subtracts x times the milliseconds of a day, but also checks for clock changes and
automatically includes these into the calculation of the future or past date.
- Parameters:
- {Number} days
- The number of days to be added to or subtracted from the current date.
- Returns:
- {M.Date} The current date, x days in the future (based on parameter 'days').
{String}
format(format, utc)
This method formats a given date object according to the passed 'format' property and
returns it as a String.
The following list defines the special characters that can be used in the 'format' property
to format the given date:
d Day of the month as digits; no leading zero for single-digit days.
dd Day of the month as digits; leading zero for single-digit days.
ddd Day of the week as a three-letter abbreviation.
dddd Day of the week as its full name.
m Month as digits; no leading zero for single-digit months.
mm Month as digits; leading zero for single-digit months.
mmm Month as a three-letter abbreviation.
mmmm Month as its full name.
yy Year as last two digits; leading zero for years less than 10.
yyyy Year represented by four digits.
h Hours; no leading zero for single-digit hours (12-hour clock).
hh Hours; leading zero for single-digit hours (12-hour clock).
H Hours; no leading zero for single-digit hours (24-hour clock).
HH Hours; leading zero for single-digit hours (24-hour clock).
M Minutes; no leading zero for single-digit minutes.
MM Minutes; leading zero for single-digit minutes.
s Seconds; no leading zero for single-digit seconds.
ss Seconds; leading zero for single-digit seconds.
l or L Milliseconds. l gives 3 digits. L gives 2 digits.
t Lowercase, single-character time marker string: a or p.
tt Lowercase, two-character time marker string: am or pm.
T Uppercase, single-character time marker string: A or P.
TT Uppercase, two-character time marker string: AM or PM.
Z US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500
o GMT/UTC timezone offset, e.g. -0500 or +0230.
S The date's ordinal suffix (st, nd, rd, or th). Works well with d.
- Parameters:
- {String} format
- The format.
- {Boolean} utc
- Determines whether to convert to UTC time or not. Default: NO.
- Returns:
- {String} The date, formatted with a given format.
{M.Date}
hoursFromDate(hours)
This method returns a date in the future or past, based on 'hours' and a given date. Basically
it adds or subtracts x hours, but also checks for clock changes and automatically includes
these into the calculation of the future or past date.
- Parameters:
- {Number} hours
- The number of hours to be added to or subtracted from the current date.
- Returns:
- {M.Date} The date, x hours in the future (based on parameter 'hours').
{M.Date}
hoursFromNow(hours)
This method returns a date in the future or past, based on 'hours'. Basically it adds or
subtracts x times the milliseconds of an hour, but also checks for clock changes and
automatically includes these into the calculation of the future or past date.
- Parameters:
- {Number} hours
- The number of hours to be added to or subtracted from the current date.
- Returns:
- {M.Date} The current date, x hours in the future (based on parameter 'hours').
{M.Date}
millisecondsFromDate(milliseconds)
This method returns a date in the future or past, based on 'milliseconds' and a given date. Basically
it adds or subtracts x milliseconds, but also checks for clock changes and automatically includes
these into the calculation of the future or past date.
- Parameters:
- {Number} milliseconds
- The number of milliseconds to be added to or subtracted from the current date.
- Returns:
- {M.Date} The date, x milliseconds in the future (based on parameter 'milliseconds').
{M.Date}
millisecondsFromNow(milliseconds)
This method returns a date in the future or past, based on 'milliseconds'. Basically it adds or
subtracts x milliseconds, but also checks for clock changes and automatically includes these
into the calculation of the future or past date.
- Parameters:
- {Number} milliseconds
- The number of milliseconds to be added to or subtracted from the current date.
- Returns:
- {M.Date} The current date, x milliseconds in the future (based on parameter 'milliseconds').
{M.Date}
minutesFromDate(minutes)
This method returns a date in the future or past, based on 'minutes' and a given date. Basically
it adds or subtracts x minutes, but also checks for clock changes and automatically includes
these into the calculation of the future or past date.
- Parameters:
- {Number} minutes
- The number of minutes to be added to or subtracted from the current date.
- Returns:
- {M.Date} The date, x minutes in the future (based on parameter 'minutes').
{M.Date}
minutesFromNow(minutes)
This method returns a date in the future or past, based on 'minutes'. Basically it adds or
subtracts x times the milliseconds of a minute, but also checks for clock changes and
automatically includes these into the calculation of the future or past date.
- Parameters:
- {Number} minutes
- The number of minutes to be added to or subtracted from the current date.
- Returns:
- {M.Date} The current date, x minutes in the future (based on parameter 'minutes').
{M.Date}
now()
Returns the current date, e.g.
Thu Nov 11 2010 14:20:55 GMT+0100 (CET)
- Returns:
- {M.Date} The current date.
{M.Date}
secondsFromDate(seconds)
This method returns a date in the future or past, based on 'seconds' and a given date. Basically
it adds or subtracts x seconds, but also checks for clock changes and automatically includes
these into the calculation of the future or past date.
- Parameters:
- {Number} seconds
- The number of seconds to be added to or subtracted from the current date.
- Returns:
- {M.Date} The date, x seconds in the future (based on parameter 'seconds').
{M.Date}
secondsFromNow(seconds)
This method returns a date in the future or past, based on 'seconds'. Basically it adds or
subtracts x times the milliseconds of a second, but also checks for clock changes and
automatically includes these into the calculation of the future or past date.
- Parameters:
- {Number} seconds
- The number of seconds to be added to or subtracted from the current date.
- Returns:
- {M.Date} The current date, x seconds in the future (based on parameter 'seconds').
{Number}
timeBetween(date, returnType)
This method returns the time between two dates, based on the given returnType.
Possible returnTypes are:
- M.MILLISECONDS: milliseconds
- M.SECONDS: seconds
- M.MINUTES: minutes
- M.HOURS: hours
- M.DAYS: days
- Parameters:
- {Object} date
- The date.
- {String} returnType
- The return type for the call.
- Returns:
- {Number} The time between the two dates, computed as what is specified by the 'returnType' parameter.
{M.Date}
tomorrow()
This method returns the date, 24h in the future.
- Returns:
- {M.Date} The current date, 24 hours in the future.
{M.Date}
yesterday()
This method returns the date, 24h in the past.
- Returns:
- {M.Date} The current date, 24 hours in the past.