// Returns integer values the day differences negative reference to past no. of days from current day.
function dayDifferenceFromCurrent (date) {
var now = new Date();
return date.getDate() – now.getDate()
}
// Returns integer values the hour differences negative reference to past no. of days from current hour.
function hoursDifferenceFromCurrent (date) {
var now = new Date();
return date.getHours() – now.getHours()
}
// Default format
var start = new Date();
Sun Jan 03 2016 10:52:48 GMT+0530 (India Standard Time)
Date Set Methods
Set methods are used for setting a part of a date. Here are the most common (alphabetically):
| Method | Description |
|---|---|
| setDate() | Set the day as a number (1-31) |
| setFullYear() | Set the year (optionally month and day) |
| setHours() | Set the hour (0-23) |
| setMilliseconds() | Set the milliseconds (0-999) |
| setMinutes() | Set the minutes (0-59) |
| setMonth() | Set the month (0-11) |
| setSeconds() | Set the seconds (0-59) |
| setTime() | Set the time (milliseconds since January 1, 1970) |
Date Get Methods
Get methods are used for getting a part of a date. Here are the most common (alphabetically):
| Method | Description |
|---|---|
| getDate() | Get the day as a number (1-31) |
| getDay() | Get the weekday as a number (0-6) |
| getFullYear() | Get the four digit year (yyyy) |
| getHours() | Get the hour (0-23) |
| getMilliseconds() | Get the milliseconds (0-999) |
| getMinutes() | Get the minutes (0-59) |
| getMonth() | Get the month (0-11) |
| getSeconds() | Get the seconds (0-59) |
| getTime() | Get the time (milliseconds since January 1, 1970) |
UTC Date Methods
UTC date methods are used for working UTC dates (Univeral Time Zone dates):
| Method | Description |
|---|---|
| getUTCDate() | Same as getDate(), but returns the UTC date |
| getUTCDay() | Same as getDay(), but returns the UTC day |
| getUTCFullYear() | Same as getFullYear(), but returns the UTC year |
| getUTCHours() | Same as getHours(), but returns the UTC hour |
| getUTCMilliseconds() | Same as getMilliseconds(), but returns the UTC millisecons |
| getUTCMinutes() | Same as getMinutes(), but returns the UTC minutes |
| getUTCMonth() | Same as getMonth(), but returns the UTC month |
| getUTCSeconds() | Same as getSeconds(), but returns the UTC seconds |
Time Zones
JavaScript accepts these time zones:
| Time Zone | Description |
|---|---|
| UTC | Coordinated Universal Time |
| GMT | Greenwich Mean Time |
| EDT | (US) Eastern Daylight Time |
| CDT | (US) Central Daylight Time |
| MDT | (US) Mountain Daylight Time |
| PDT | (US) Pacific Daylight Time |
| EST | (US) Eastern Standard Time |
| CST | (US) Central Standard Time |
| MST | (US) Mountain Standard Time |
| PST | (US) Pacific Standard Time |
