How to realize date output by JavaScript
This article mainly explains "how to achieve date output by JavaScript". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "JavaScript how to achieve date output" bar!
By default, JavaScript uses the browser's time zone and displays the date as a full-text string:
Tue Apr 02 2019 09:01:19 GMT+0800 (China Standard time)
Later, you will learn more about how to display dates in this tutorial.
Create a Date object
The Date object is created by the new Date () constructor.
There are four ways to create a new date object:
New Date ()
New Date (year, month, day, hours, minutes, seconds, milliseconds)
New Date (milliseconds)
New Date (date string)
New Date ()
New Date () creates a new date object with the current date and time:
Example
Var d = new Date ()
The date object is static. The computer time is ticking, but the date object will not.
New Date (year, month, … )
New Date (year, month, … Creates a new date object with the specified date and time
Seven numbers specify year, month, day, hour, minute, second, and millisecond (in this order):
Example
Var d = new Date (2018, 11, 24, 10, 33, 30, 0)
6 numbers specify year, month, day, hour, minute, second:
Example
Var d = new Date (2018, 11, 24, 10, 33, 30)
5 numbers specify year, month, day, hour and minute:
Example
Var d = new Date (2018, 11, 24, 10, 33)
Four numbers specify the year, month, day and hour:
Example
Var d = new Date (2018, 11, 24, 10)
Three numbers specify the year, month and day:
Example
Var d = new Date (2018, 11, 24)
2 digits specify the year and month:
Example
Var d = new Date (2018, 11)
You cannot omit the month. If only one parameter is provided, it is treated as milliseconds.
At this point, I believe you have a deeper understanding of "JavaScript how to achieve date output", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!