×

Html & Html5

it training classes Logo

The World's best Software Development Study Portal

Js Date


It is the type of an object which we can used to get year , month and day. We can display the date, day, month , hour and seconds. We have some ways to create the date using the date constructor which are described as follows:-:-

  • Date()
  • Date(milliseconds)
  • Date(datestring)
  • Date(year, month, day, hours, minutes, seconds, milliseconds)
Let's take an example:-

<html>

<body>

Current Date and Time: <span id="txt"></span>

<script>

var today=new Date();

document.getElementById('txt').innerHTML=today;

</script>

</body>

</html>

Output of this program

Current Date and Time:



Let's take another example:-

<html>

<body>

<script> var date=new Date();

var day=date.getDate();

var month=date.getMonth()+1;

var year=date.getFullYear();

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

</script>

</body>

</html>

Output of this program







Some more methods and description below :-

Methods Description
getDate() It returns the integer value between 1 and 31 that represents the day for the specified date on the basis of local time.
getDay() It returns the integer value between 0 and 6 that represents the day of the week on the basis of local time.
getFullYears() It returns the integer value that represents the year on the basis of local time.
getHours() It returns the integer value between 0 and 23 that represents the hours on the basis of local time.
getMilliseconds() It returns the integer value between 0 and 999 that represents the milliseconds on the basis of local time.
getMinutes() It returns the integer value between 0 and 59 that represents the minutes on the basis of local time.
replace() It replaces a given string with the specified replacement.
getMonth() It returns the integer value between 0 and 11 that represents the month on the basis of local time.
setDate() It sets the day value for the specified date on the basis of local time.
setDay() It sets the particular day of the week on the basis of local time.
setMonth() It sets the month value for the specified date on the basis of local time.
setSeconds() It sets the second value for the specified date on the basis of local time.






JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute