Date process permit you to get and set date values (years, months, days, hours, minutes, seconds, milliseconds)

JavaScript – The Date Object

Here’s a description of the parameters −

  • No Argument − With no arguments, the Date() constructor creates a Date object set to the present date and time.
  • milliseconds − When one numeric argument is handed, it’s taken as the inner numeric illustration of the date in milliseconds, as returned by the getTime() technique. For instance, passing the argument 5000 creates a date that represents 5 seconds previous midnight on 1/1/70.
  • datestring − When one string argument is handed, it’s a string illustration of a date, within the format accepted by the Date.parse() technique.
  • 7 agruments − To make use of the final type of the constructor proven above. Here’s a description of every argument −
    • 12 months − Integer worth representing the 12 months. For compatibility (with a view to keep away from the Y2K downside), you need to all the time specify the 12 months in full; use 1998, fairly than 98.
    • month − Integer worth representing the month, starting with zero for January to 11 for December.
    • date − Integer worth representing the day of the month.
    • hour − Integer worth representing the hour of the day (24-hour scale).
    • minute − Integer worth representing the minute section of a time studying.
    • second − Integer worth representing the second section of a time studying.
    • millisecond − Integer worth representing the millisecond section of a time studying.

JavaScript Date Examples:

<!DOCTYPE html>
<html>
<body>

<p>The internal clock in JavaScript starts at midnight January 1, 1970.</p>
<p>The getTime() function returns the number of milliseconds since then:</p>

<p id="demo"></p>

<script>
var d = new Date();
document.getElementById("demo").innerHTML = d.getTime();
</script>

</body>
</html>

getFullYear() returns the year of a date as a four digit number:

<!DOCTYPE html>
<html>
<body>

<p>The getFullYear() method returns the full year of a date:</p>

<p id="demo"></p>

<script>
var d = new Date();
document.getElementById("demo").innerHTML = d.getFullYear();
</script>

</body>
</html>

getDay() returns the weekday as a number (0-6):

<!DOCTYPE html>
<html>
<body>

<p>The getDay() method returns the weekday as a number:</p>

<p id="demo"></p>

<script>
var d = new Date();
document.getElementById("demo").innerHTML = d.getDay();
</script>

</body>
</html>

Premium JavaScript Date Methods:

$6.00
Codecanyon.net
(25)
$19.00
Codecanyon.net
$17.00
Themeforest.net
$17.00
Codecanyon.net
(28)
$17.00
Codecanyon.net
Learn Complete With W3schools

About The Author

Related Posts

Leave a Reply

Your email address will not be published.