JavaScript Set Date Methos/ Functions- Today we discuss about javascript set date methods. When we want to set or get date value that time we are used javascript date methods. Javascript date Methods can be expressed in years, months, days, hours, minutes, seconds or milliseconds.
The Javascript set date methods are an inbuilt function in JavaScript which returns the number of milliseconds since
Set Date Methods JavaScript
- setFullYear()
- setMonth()
- setDate()
- setHours()
- setMinutes()
- setSeconds()
- setMilliseconds()
The setFullYear()
The JavaScript setFullYear() is an inbuilt function of JavaScript which is used to set a year into a date object.
The setFullYear() Syntax
DateObj.setFullYear(set_year);
Example
var today = new Date(); document.write("Today: "+today); document.write("<br />"); today.setFullYear(today.getFullYear() - 1); document.write("1 Year Before: "+today);
The setMonth()
The JavaScript setMonth() is an inbuilt function of JavaScript. which is used to set month into a date object.
The setMonth() Syntax
DateObj.setMonth(set_month);
Example
var d=new Date(); d.setMonth(0); document.write("Set Month: "+d);
The setDate()
The JavaScript setDate() is an inbuilt function of JavaScript. which is used to sets the day of the month of this date object.
The setDate() Syntax
DateObj.setDate(set_date);
Example
var d=new Date(); d.setDate(5); document.write("Set Date: "+d);
The setHours() Method
The JavaScript setHours() is an inbuilt function of JavaScript. which is used to sets the hour of a date object.
The setHours() Syntax
DateObj.setHours(set_hour);
Example
var d=new Date(); d.setHours(10); document.write("Set Hours: "+d);
The setMinutes()
The JavaScript setMinutes() is an inbuilt function of JavaScript. which is used to set minute into a date object.
The setMinutes() Syntax
DateObj.setMinutes(set_minutes);
Example
var d=new Date(); d.setMinutes(22); document.write("Set Minutes: "+d);
The setSeconds()
The setSeconds() Method – sets the seconds of a date object. This is a inbuilt function of JavaScript.
The setHours() Syntax
DateObj.setSeconds(set_seconds);
Example
var d=new Date(); d.setSeconds(10); document.write("Set Seconds: "+d);
The setMilliseconds()
The setMilliseconds() Method – sets the milliseconds of a date object.
The setMilliseconds() Syntax
DateObj.setMilliseconds(set_milliseconds);
Example
var d=new Date(); d.setMilliseconds(55); document.write("Set Milli Seconds: "+d);