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)
Count(*) or Count(1) or Count([column]) are perha...
Look at the code first Copy code The code is as fo...
After a lot of trouble, I finally figured out the...
1. Command Introduction The seq (Sequence) comman...
Today's article mainly introduces the reload ...
Table of contents Business requirements: Solution...
Virtual machines are very convenient testing soft...
Preface: This article refers to jackyzm's blo...
Docker view process, memory, cup consumption Star...
Table of contents Preface question Online solutio...
Operating system win10 MySQL is the 64-bit zip de...
Table of contents Intro Nginx Dockerfile New conf...
Writing XHTML demands a clean HTML syntax. Writing...
Using provide+inject combination in Vue First you...
Table of contents splice() Method join() Method r...