Date ObjectUse Date object to represent a time in JS Creating a Date Objectnew Date()Creating a Date object If you use the constructor to create a Date object, it will encapsulate the time when the current code is executed. var d = new Date(); console.log("Current time is:",d); Create a specified time object You need to pass a string representing the time as a parameter in the constructor Date format month/day/year (hour:minute:second) var d = new Date("12/21/2012 12:12:30"); console.log("The Mayans predicted the end of the world:",d); You can also create it by passing parameters The syntax is var d = new Date(2012,11,21,8,00,00); console.log(d); Notice: The integer value of the month of the time created by parameter passing, from 0 (January) to 11 (December) getDate()Get the date of the current object var d = new Date("12/21/2012 12:12:30"); var date = d.getDate() console.log("What is the date of object d:", date); getDay()
var d = new Date("12/21/2012 12:12:30"); var date = d.getDay() console.log("What day of the week is object d: ", date); getMonth()
var d = new Date("12/21/2012 12:12:30"); var date = d.getMonth() console.log("The month of the current time object is:", date); //Returns a number from 0 to 11, 11 represents December getFullYear()
var d = new Date("12/21/2012 12:12:30"); var date = d.getFullYear() console.log("Year of the current time object:", date); getHours()
getMinutes()
getSeconds()
getMilliseconds()
getTime()
var d = new Date("12/21/2012 11:10:30"); var date = d.getTime() console.log("Year of the current time object:", date); Date.now()
var start = Date.now(); for (let i = 0; i < 100; i++) { console.log(i); } var end = Date.now(); console.log("The statement was executed: "+(end - start)+" milliseconds"); toDateString()
toLocaleDateString()
SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Control the vertical center of the text in the HTML text box through CSS
>>: Solution for converting to inline styles in CSS (css-inline)
1. The relationship between fonts and character d...
Table of contents Preface First look at React Con...
Table of contents Question: 1. First attempt 2. R...
one: 1. Semantic tags are just HTML, there is no ...
Preface Readers who are familiar with MySQL may f...
Method 1: Use script method: Create a common head...
Firewall A firewall is a set of rules. When a pac...
1. One-click installation of Mysql script [root@u...
Table of contents Character Set Comparison Rules ...
Today I recommend such an open source tool for ex...
Method 1: Command line modification We only need ...
How background-position affects the display of ba...
Environmental Statement Host OS: Cetnos7.9 Minimu...
This article shares the specific code of Vue to r...
1. Run fonts, open the font folder, and find the ...