Date() function in javaScript

It is an object which used to find the year, month and date. In this we will learn how to date Date constructor used to implement Date object:

Date constructor used with four variant:

  • Date()  

  • Date(milliseconds)  

  • Date(dateString)  

  • Date(year, month, day, hours, minutes, seconds, milliseconds)  

Date methods: In this several methods is pre-exist here we will learn some important methods which is given below:

 

getDate(), getDay(), getFullYear, getHours(), getMilliseconds(), getMinute(), getMonth(), getSeconds().

 

getUTCDate()-

It returns the integer value between 1 and 31 that represents the day for the specified date on the basis of universal time.

 

Similar “get” all function used with UTC.

setDate()-

It sets the day value for the specified date on the basis of local time.

Similar “get” and  “UTC” function used with “set” .for ex. setUTCHours()

Ex.

<script>  

var date=new Date();  

var day=date.getDate();  

var month=date.getMonth()+1;  

var year=date.getFullYear();  

document.write("<br>Date is: "+day+"/"+month+"/"+year);  

</script>

Powered  by Codersarts