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. Use absolute positioning and margin The princi...
Table of contents 1. v-text (v-instruction name =...
Serve: # chkconfig --list List all system service...
disabled definition and usage The disabled attrib...
Preface I wrote a small demo today. There is a pa...
This is a very simple pure CSS3 white cloud float...
Problem description (the following discussion is ...
When we develop a single-page application, someti...
Analyze the execution process. Move the mouse int...
When the created tab label exceeds the visible ar...
This article shares the MySQL 5.7.18 MSI installa...
The computer system is: win7 This article is main...
During the Olympic Games, IE 8 Beta 2 will be rele...
Problem: When using JDBC to connect to the MySQL ...