Add number of days to date in javascript
var CurrentDate = new Date(); var numberOfDaysToAdd = 6; CurrentDate.setDate(CurrentDate.getDate() + numberOfDaysToAdd);
Add number of months to date in javascript
var CurrentDate = new Date(); var numberOfMonthsToAdd = 12; CurrentDate.setMonth(CurrentDate.getMonth() + numberOfMonthsToAdd);
Add number of minutes to date in javascript
var twentyMinutesLater = new Date(); twentyMinutesLater.setMinutes(twentyMinutesLater.getMinutes() + 20);
<script> var d = new Date(); var date_var = d.getFullYear()+'-'+d.getMonth()+'-'+d.getDate()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds(); // format year-month-day hours:minutes:seconds alert(date_var); // return '2012-10-25 10:45:37' </script>
|
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. |
|
setDate |
Sets the day of the month (1-31) for a specified date according to local time. |
|
setFullYear |
Sets the full year (4 digits for 4-digit years) for a specified date according to local time. |
|
setHours |
Sets the hours (0-23) for a specified date according to local time. |
|
setMilliseconds |
Sets the milliseconds (0-999) for a specified date according to local time. |
|
setMinutes |
Sets the minutes (0-59) for a specified date according to local time. |
|
setMonth |
Sets the month (0-11) for a specified date according to local time. |
|
setSeconds |
Sets the seconds (0-59) for a specified date according to local time. |
|
setTime |
Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC, allowing for negative numbers for times prior. |
|
setUTCDate |
Sets the day of the month (1-31) for a specified date according to universal time. |
|
setUTCFullYear |
Sets the full year (4 digits for 4-digit years) for a specified date according to universal time. |
|
setUTCHours |
Sets the hour (0-23) for a specified date according to universal time. |
|
setUTCMilliseconds |
Sets the milliseconds (0-999) for a specified date according to universal time. |
|
setUTCMinutes |
Sets the minutes (0-59) for a specified date according to universal time. |
|
setUTCMonth |
Sets the month (0-11) for a specified date according to universal time. |
|
setUTCSeconds |
Sets the seconds (0-59) for a specified date according to universal time. |
|
toDateString |
Returns the "date" portion of the Date as a human-readable string. |
|
toISOString |
Converts a date to a string following the ISO 8601 Extended Format. |
|
toJSON (requires JavaScript 1.8.5) |
Returns a string encapsulating the Date object in JSON format. |
|
toLocaleDateString |
Returns the "date" portion of the Date as a string, using the current locale's conventions. |
|
toLocaleFormat (Non-standard) |
Converts a date to a string, using a format string. |
|
toLocaleString |
Converts a date to a string, using the current locale's conventions. Overrides the Object.toLocaleString method. |
|
toLocaleTimeString |
Returns the "time" portion of the Date as a string, using the current locale's conventions. |
|
toSource (Non-standard) |
Returns a string representing the source for an equivalent Date object; you can use this value to create a new object. Overrides the Object.prototype.toSource method. |
|
toString |
Returns a string representing the specified Date object. Overrides the Object.prototype.toString method. |
|
toTimeString |
Returns the "time" portion of the Date as a human-readable string. |
|
toUTCString |
Converts a date to a string, using the universal time convention. |