toUTCString()
|
Same as toString() but in universal time. Here's how Pacific Standard (PST) local time differs from UTC:
> var d = new Date(2015, 0, 1);
> d.toString();
"Thu Jan 01 2015 00:00:00 GMT-0800 (PST)"
> d.toUTCString();
"Thu, 01 Jan 2015 08:00:00 GMT"
|
toDateString()
|
Returns only the date portion of toString() :
> new Date(2015, 0, 1).toDateString();
"Thu Jan 01 2010"
|
toTimeString()
|
Returns only the time portion of toString() :
> new Date(2015, 0, 1).toTimeString();
"00:00:00 GMT-0800 (PST)"
|
toLocaleString()
toLocaleDateString()
toLocaleTimeString()
|
Equivalent to toString() , toDateString() , and toTimeString() respectively, but in a friendlier format, according to the current user's locale.
> new Date(2015, 0, 1).toString();
"Thu Jan 01 2015 00:00:00 GMT-0800 (PST)"
> new Date(2015, 0, 1).toLocaleString();
"1/1/2015 12:00:00 AM"
|
getTime()
setTime(time)
|
Get or set the time (using a timestamp) of a date object. The following example creates a date and moves it one day forward:
> var d = new Date(2015, 0, 1);
> d.getTime();
1420099200000
> d.setTime(d.getTime()+ 1000 * 60 * 60 * 24);
1420185600000
> d.toLocaleString();
"Fri Jan 02 2015 00:00:00 GMT-0800 (PST)"
|
getFullYear()
getUTCFullYear()
setFullYear(year, month, date)
setUTCFullYear(year, month, da
te)
|
Get or set a full year using local or UTC time. There is also getYear() but it is not Y2K compliant, so use getFullYear() instead.
> var d = new Date(2015, 0, 1);
> d.getYear();
115
> d.getFullYear();
2015
> d.setFullYear(2020);
1577865600000
> d;
Wed Jan 01 2020 00:00:00 GMT-0800 (PST)
|
getMonth()
getUTCMonth()
setMonth(month, date)
setUTCMonth(month, date)
|
Get or set the month, starting from 0 (January):
> var d = new Date(2015, 0, 1);
> d.getMonth();
0
> d.setMonth(11);
1448956800000
> d.toLocaleDateString();
"12/1/2015"
|
getDate()
getUTCDate()
setDate(date)
setUTCDate(date)
|
Get or set the date of the month.
> var d = new Date(2015, 0, 1);
> d.toLocaleDateString();
"1/1/2015"
> d.getDate();
1
> d.setDate(31);
1422691200000
> d.toLocaleDateString();
"1/31/2015"
|
getHours()
getUTCHours()
setHours(hour, min, sec, ms)
setUTCHours(hour, min, sec, ms)
getMinutes()
getUTCMinutes()
setMinutes(min, sec, ms)
setUTCMinutes(min, sec, ms)
getSeconds()
getUTCSeconds()
setSeconds(sec, ms)
setUTCSeconds(sec, ms)
getMilliseconds()
getUTCMilliseconds()
setMilliseconds(ms)
setUTCMilliseconds(ms
)
|
Get or set the hour, minutes, seconds, milliseconds, all starting from 0.
> var d = new Date(2015, 0, 1);
> d.getHours() + ':' + d.getMinutes();
"0:0"
> d.setMinutes(59);
1420102740000
> d.getHours() + ':' + d.getMinutes();
"0:59"
|
getTimezoneOffset()
|
Returns the difference between local and universal (UTC) time, measured in minutes. For example, the difference between PST (Pacific Standard Time) and UTC:
> new Date().getTimezoneOffset();
480
> 420 / 60; // hours
8
|
getDay()
getUTCDay(
)
|
Returns the day of the week, starting from 0 (Sunday):
> var d = new Date(2015, 0, 1);
> d.toDateString();
"Thu Jan 01 2015"
> d.getDay();
4
> var d = new Date(2015, 0, 4);
> d.toDateString();
"Sat Jan 04 2015"
> d.getDay();
0
|