Javascript Date: Difference between revisions

From Yate Documentation
Jump to navigation Jump to search
Created page with "Date class in Yate's Javascript implementation. ==Constructor== new Date(); new Date(value); new Date(year, month [, day, hour, minute, second, millisecond]); Where: * va..."
 
Marian (talk | contribs)
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Date class in Yate's Javascript implementation.
Date class in Yate's Javascript implementation.


==Constructor==
== Constructor ==
new Date();
* '''new Date()'''
new Date(value);
* '''new Date(value)'''
new Date(year, month [, day, hour, minute, second, millisecond]);
* '''new Date(str)'''
* '''new Date(year, month [, day, hour, minute, second, milliseconds])'''


Where:
Where:
* value - Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).  
Parameters:<br/>
* '''value''' Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
* '''str''' String describing the date. See format below. Handled as Unix Epoch time.
* '''year''' Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999.
* '''month''' Integer value representing the month, beginning with 0 for January to 11 for December.
* '''day''' Integer value representing the day of the month.
* '''hour''' Integer value representing the hour of the day.
* '''minute''' Integer value representing the minute segment of a time.
* '''second''' Integer value representing the second segment of a time.
* '''milliseconds''' Integer value representing the milliseconds segment of a time.


* year - Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999.  
If no arguments are provided, the constructor creates a JavaScript Date object '''for the current date and time according to system settings'''.


* month - Integer value representing the month, beginning with 0 for January to 11 for December.


* day - Integer value representing the day of the month.
String format:
yyyy-mm-ddThh:mm:ss[.SEC-FRAC]Z
yyyy-mm-ddThh:mm:ss[.SEC-FRAC]{+/-}hh:mm


* hour - Integer value representing the hour of the day.
Notes:<br/>
T and Z are case insensitive (t and z are may be given).<br/>
SEC-FRAC: Optional second fractions (milliseconds).<br/>
The second format indicates a timezone (hours:minutes) offset. Held time will be increased or decreased with given timezone offset value.<br/>


* minute - Integer value representing the minute segment of a time.


* second - Integer value representing the second segment of a time.
Examples:
  new Date("2010-01-01T00:10:01Z");
  new Date("2010-01-01T00:10:01.500Z");
  new Date("2010-01-01T00:10:01+00:03");
  new Date("2010-01-01T00:10:01.500+00:03");
  new Date("2010-01-01T00:10:01.500-00:03");


* millisecond - Integer value representing the millisecond segment of a time.
The following lead to constructor failure (return null):
  new Date("1010-01-01T00:10:01Z"); // Date before Unix Epoch
  new Date("1970-01-01T00:10:01-23:00"); // Date before Unix Epoch after applying timezone offset


==Methods==
== Static methods ==


*   'getDate'
* '''Date.now()'''
*   'getDay'
Static method Date.now() returns Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch)
*   'getFullYear'
 
*   'getHours'
 
*   'getMilliseconds'
* '''UTC(year, month [, day, [,hour, [,minute, [,second, [,milliseconds]]]]])'''
*   'getMinutes'
Build Unix Epoch time from components.<br/>
*   'getMonth'
Parameters:<br/>
*   'getSeconds'
* '''year''' Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999.
*   'getTime'
* '''month''' Integer value representing the month, beginning with 0 for January to 11 for December.
*   'getTimezoneOffset'
* '''day''' Integer value representing the day of the month.
*   'getUTCDate'
* '''hour''' Integer value representing the hour of the day.
*   'getUTCDay'
* '''minute''' Integer value representing the minute segment of a time.
*   'getUTCFullYear'
* '''second''' Integer value representing the second segment of a time.
*   'getUTCHours'
* '''milliseconds''' Integer value representing the milliseconds segment of a time.
*   'getUTCMilliseconds'
Return:<br/>
*   'getUTCMinutes'
Success: integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).<br/>
*   'getUTCMonth'
Failure: '''NaN''' (invalid parameters).<br/>
*   'getUTCSeconds'
 
 
== Methods ==
 
* '''getDate'''
Returns the day of the month (1-31) for the specified date according to local time.
 
* '''getDay'''
Returns the day of the week (0-6) for the specified date according to local time.
 
* '''getFullYear'''
Returns the year (4 digits for 4-digit years) of the specified date according to local time.
 
* '''getHours'''
Returns the hour (0-23) in the specified date according to local time.
 
* '''getMilliseconds'''
Returns the milliseconds (0-999) in the specified date according to local time.
 
* '''getMinutes'''
Returns the minutes (0-59) in the specified date according to local time.
 
* '''getMonth'''
Returns the month (0-11) in the specified date according to local time.
 
* '''getSeconds'''
Returns the seconds (0-59) in the specified date according to local time.
 
* '''getTime'''
Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC (negative for prior times).
 
* '''getTimezoneOffset'''
Returns the time-zone offset in minutes for the current locale.
 
* '''getUTCDate'''
Returns the day (date) of the month (1-31) in the specified date according to universal time.
 
* '''getUTCDay'''
Returns the day of the week (0-6) in the specified date according to universal time.
 
* '''getUTCFullYear'''
Returns the year (4 digits for 4-digit years) in the specified date according to universal time.
 
* '''getUTCHours'''
Returns the hours (0-23) in the specified date according to universal time.
 
* '''getUTCMilliseconds'''
Returns the milliseconds (0-999) in the specified date according to universal time.
 
* '''getUTCMinutes'''
Returns the minutes (0-59) in the specified date according to universal time.
 
* '''getUTCMonth'''
Returns the month (0-11) in the specified date according to universal time.
 
* '''getUTCSeconds'''
Returns the seconds (0-59) in the specified date according to universal time.
 
* '''toJSON()'''
Returns formatted string with date description.
 
Example:
var d = new Date(1262304601900);
var s = d.toJSON();
// s contents: 2010-01-01T00:10:01.900Z
 
 
[[Category:Javascript]]

Latest revision as of 10:38, 9 September 2024

Date class in Yate's Javascript implementation.

Constructor

  • new Date()
  • new Date(value)
  • new Date(str)
  • new Date(year, month [, day, hour, minute, second, milliseconds])

Where: Parameters:

  • value Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
  • str String describing the date. See format below. Handled as Unix Epoch time.
  • year Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999.
  • month Integer value representing the month, beginning with 0 for January to 11 for December.
  • day Integer value representing the day of the month.
  • hour Integer value representing the hour of the day.
  • minute Integer value representing the minute segment of a time.
  • second Integer value representing the second segment of a time.
  • milliseconds Integer value representing the milliseconds segment of a time.

If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings.


String format:

yyyy-mm-ddThh:mm:ss[.SEC-FRAC]Z
yyyy-mm-ddThh:mm:ss[.SEC-FRAC]{+/-}hh:mm

Notes:
T and Z are case insensitive (t and z are may be given).
SEC-FRAC: Optional second fractions (milliseconds).
The second format indicates a timezone (hours:minutes) offset. Held time will be increased or decreased with given timezone offset value.


Examples:

 new Date("2010-01-01T00:10:01Z");
 new Date("2010-01-01T00:10:01.500Z");
 new Date("2010-01-01T00:10:01+00:03");
 new Date("2010-01-01T00:10:01.500+00:03");
 new Date("2010-01-01T00:10:01.500-00:03");

The following lead to constructor failure (return null):

 new Date("1010-01-01T00:10:01Z"); // Date before Unix Epoch
 new Date("1970-01-01T00:10:01-23:00"); // Date before Unix Epoch after applying timezone offset

Static methods

  • Date.now()

Static method Date.now() returns Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch)


  • UTC(year, month [, day, [,hour, [,minute, [,second, [,milliseconds]]]]])

Build Unix Epoch time from components.
Parameters:

  • year Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999.
  • month Integer value representing the month, beginning with 0 for January to 11 for December.
  • day Integer value representing the day of the month.
  • hour Integer value representing the hour of the day.
  • minute Integer value representing the minute segment of a time.
  • second Integer value representing the second segment of a time.
  • milliseconds Integer value representing the milliseconds segment of a time.

Return:
Success: integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
Failure: NaN (invalid parameters).


Methods

  • getDate

Returns the day of the month (1-31) for the specified date according to local time.

  • getDay

Returns the day of the week (0-6) for the specified date according to local time.

  • getFullYear

Returns the year (4 digits for 4-digit years) of the specified date according to local time.

  • getHours

Returns the hour (0-23) in the specified date according to local time.

  • getMilliseconds

Returns the milliseconds (0-999) in the specified date according to local time.

  • getMinutes

Returns the minutes (0-59) in the specified date according to local time.

  • getMonth

Returns the month (0-11) in the specified date according to local time.

  • getSeconds

Returns the seconds (0-59) in the specified date according to local time.

  • getTime

Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC (negative for prior times).

  • getTimezoneOffset

Returns the time-zone offset in minutes for the current locale.

  • getUTCDate

Returns the day (date) of the month (1-31) in the specified date according to universal time.

  • getUTCDay

Returns the day of the week (0-6) in the specified date according to universal time.

  • getUTCFullYear

Returns the year (4 digits for 4-digit years) in the specified date according to universal time.

  • getUTCHours

Returns the hours (0-23) in the specified date according to universal time.

  • getUTCMilliseconds

Returns the milliseconds (0-999) in the specified date according to universal time.

  • getUTCMinutes

Returns the minutes (0-59) in the specified date according to universal time.

  • getUTCMonth

Returns the month (0-11) in the specified date according to universal time.

  • getUTCSeconds

Returns the seconds (0-59) in the specified date according to universal time.

  • toJSON()

Returns formatted string with date description.

Example:

var d = new Date(1262304601900);
var s = d.toJSON();
// s contents: 2010-01-01T00:10:01.900Z