0% found this document useful (0 votes)
13 views3 pages

Datetime

Uploaded by

Mahi Singhvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Datetime

Uploaded by

Mahi Singhvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1) getTime()

The getTime() method returns the number of milliseconds since


January 1, 1970:

2) getMonth()

The getMonth() method returns the month of a date as a number (0-


11):

3) getDate()
The getDate() method returns the day of a date as a number (1-31):

4) getHours()
The getHours() method returns the hours of a date as a number (0-
23):

5) setDate()

The setDate() method sets the day of a date object (1-31):

6) setHours()
The setHours() method sets the hours of a date object (0-23):

7) setMinuites()
The setMinutes() method sets the minutes of a date object (0-59):

<!DOCTYPE html>

<html>
<body>
The getDate() method returns the day of a date as a number (1-31)
<p id="demo"></p>
<p id="demo1"></p>

<script>
const d = new Date();
d.getHours();
document.getElementById("demo").innerHTML = d.getDate();
document.getElementById("demo1").innerHTML = d.getHours();

</script>
</body>
</html>

Output :- The getDate() method returns the day of a date as a number (1-31):

22

Set the day of the month to the last day of the previous month:

const d = new Date();


d.setDate(0);

it gives Mon Feb 28 2022 22:50:56 GMT+0530 (India Standard Time).

const d = new Date();


d.setHours(15, 35, 1);
document.getElementById("demo").innerHTML = d;

Mon Mar 21 2022 15:35:01 GMT+0530 (India Standard Time)

const d = new Date();


d.setHours(d.getHours() - 48);
const d = new Date();
d.setTime(1332403882588);

Thu Mar 22 2012 13:41:22 GMT+0530 (India Standard Time)

You might also like