Returns the dierence between UTC and local time. Since some countries have time
zones that are not an integer number of hours oset from UTC, the method returns
minutes rather than hours. Essentially, this method g ives you information about cur-
rent oset from UTC, which d epends o n the time zone that JavaScript is running and
whether or not daylight savings time is (or would be) eective at the moment specified
by date .
Example:
//Set the date to July (when daylight savings time is in effect):
var summer = new Date(2014, 6);
//Set the date to January (when standard time is in effect):
var winter = new Date(2014, 0);
summer.getTimezoneOffset() //Returns -120 in Vienna, -60 in London
winter.getTimezoneOffset() //Returns -60 in Vienna, 0 in London
now() //Static method
Syntax:
Date.now()
This is a static method that returns the curre nt time in milliseconds since the UNIX
epoch. Because the method is static, it is invoked directly through the Date object
itself, r ather than through particular Da te object instances.
Example:
//The following two expressions return equivalent values:
Date.now()
(new Date()).getTime()
set[UTC]Date()
Syntax:
date .setDate(dayOfMonth )
date .setUTCDate(dayOfMonth )
Sets the day of the month of the date object, using local (setDate()) or universal
(setUTCDate()) time. The dayOfMonth argument should be an integer between 1
and 31.
388 JavaScript Reference
JavaScript Reference
set[UTC]FullYear()
Syntax:
date .setFullYear(year [, month [, day ]])
date .setUTCFullYear(year [, month [, day ]])
This method sets the year field of date , using local (setFullYear()) or universal
(setUTCFulYear()) time. The year argument m ust be an integer specifying a full
year, and not an abbreviation such as 84 instead of the full 1984. Optionally, you ca n
specify month , which is an integer between 0 (January) and 11 ( D ecember), and day ,
which is an integer between 1 and 31. Note that square br ackets should not be used in
a method. T hey just indicate which arguments are optional.
set[UTC]Hours()
Syntax:
date .setHours(hours [, minutes [, seconds [, milliseconds ]]])
date .setUTCHours(hours [, minutes [, seconds [, milliseconds ]]])
This method sets the hours (and, optio nally, minutes, seconds, an d milliseconds) field
of date , using local (setHours()) or universal (setUTCHours()) time. The hours
argument sh ould be an integer betwe en 0 and 23, the minutes and seconds argu-
ments should be integers between 0 and 59, and the milliseconds argument should
be an integer between 0 and 999. Note that square brackets should not be used in a
method. They just indicate which arguments are optional.
set[UTC]Milliseconds()
Syntax:
date .setMilliseconds(milliseconds )
date .setUTCMilliseconds(milliseconds )
Allows you to set the milliseconds field of date , using local (setMilliseconds())
or universal (set UTCMilliseconds()) time. The milliseconds argument should
be an integer between 0 and 999.
set[UTC]Minutes()
Syntax:
date .setMinutes(minutes )
date .setUTCMinutes(minutes )
This method sets the minutes field of date , using local (setMinute s()) or universal
(setUTCMinutes()) time. The minutes argument should be an integer between 0
and 59.
E.6. Date (Core JavaScript) 389
set[UTC]Month()
Syntax:
date .setMonth(month )
date .setUTCMonth(month )
This method sets the month field of date , using loc al (setMonth()) or universal
(setUTCMonth()) time. The month argument should be an integer between 0 (Jan-
uary) an d 11 (December).
set[UTC]Seconds()
Syntax:
date .setSeconds(seconds )
date .setUTCSeconds(seconds )
This method sets the seconds field of date , using local (setSeconds()) or universal
(setUTCSeconds()) time. The seconds argument should be an integer between 0
and 59.
setTime()
Syntax:
date .setTime(milliseconds )
Sets the number of millisecond between the wanted date and midnight on January
1, 1970 (UTC). Because this number is independent of the time zone, no “UTC”
counterpart of this meth od exists.
to[UTC]String()
Syntax:
date .toString()
date .toUTCString()
Returns a human-readable string r epresenting the date and time stored in date . The
string is expressed in either local (toString()) or universal (toUTCString()) time.
Example:
var d = new Date();
d.toString() //Returns "Fri Jan 09 2015 16:12:22 GMT+0100
// (Central European Standard Time)"
390 JavaScript Reference
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.47.252