Built-in object date object

开发工具与关键技术:VS Date(日期)
作者:赵纯雨
班级:1804班
撰写时间:2019年 5月15日

What is an object? All things in JavaScript are objects, such as strings, arrays, values, functions, etc. Each object has properties and methods. Object properties: reflect some specific properties of the object, such as: The length of the string, the length and width of the image, etc.; the method of the object: the actions that can be performed on the object, such as the "Submit" of the form, the "getYear" of the time, etc.
Property: The length of the array is its property. Javascript provides multiple built-in objects, such as string, Date, Array, etc., which are defined before use. Use the array object as follows:
var objecName = new Array(); //= use new The keyword defines the object or var objectName = [];
The syntax for accessing object properties: objectName.propertyName
The method of accessing objects: objectName.methodNae()
The difference between the property and the method is that the property is a dskjlf.length property, and the method () is followed by The
date object in the brackets obtains a value of
1 second equal to 1000 milliseconds. There is a default initialization value that is the current computer system time. The date object can store any date and can be accurate to the number of milliseconds (1/1000 second).
Define a time object: var Udate-new Datw();
Note: Use the keyword new, the first letter of Date() must be capitalized to make Udate a date object, and it has an initial value: current time (current computer system time), If you want to customize the initial value, you can use the following method: var d = new Date(2012,10,1); or this way of writing is also OK: var d = new Date('Oct 1, 2012'); When the computer's initial Value, the format is internationalized: var Udate = new Date();
Alert(Udate); If you need a fixed date like this, you can also declare it this way, but it is still the internationalized
var d new Date(2012,10,1);
Document.write(d);
getFullYear() to get Is the four-digit year 2018, and getYear is the year 18. When getMonth gets the month, you must add 1 to it, because it starts from 0, so what you get is what you want, getDay is Week, getDate is the date:
Insert picture description here
Sunday, if you want to return the corresponding week, it is done through an array. The code returns two because the current day is the Tuesday of the computer day, getDay() returns the week, and the returned number is 0-6, 0 means next :
Insert picture description here
Set the time method, set the value
get/setTime() to return/set the time, in milliseconds, calculate the number of milliseconds from 0:00 on January 1, 1970 to the date pointed to by the date object: Insert picture description here
deepen the number of days seven days by 24 hours
Var mydate = new Date();
Document. Write("current time:" + mydate + "
");
Mydate1.setTime(mydate.getTime() + 7 24 60 60 1000); This is to deepen one hour + minutes x seconds x milliseconds
Document.write ("Delay one Time in hours: "+ mydate +"
"); Concatenate
Insert picture description here
date in the form of the same concatenated string
Declare a date, which is the current date, that is, if today is April 24, 2019, declare this date. When declaring two string variables, first get the year, month, day, hour, minute and second. The month is a bit special, from 0 to 1. Add a 1:
Get the month to determine whether it is between one and nine, and the splicing 0 in the front is 01. Insert picture description here
If (month =>1 && month <=9) { Month = "0" + month;} If (strDate => 1 && strDate <=9) { strDate = "0" + strDate; } There is one between the date Space, so use a \t var enddate = year + seperatorl + month seperatorl + strDate + "\t" + hours + seperator2 + Minute + seperator2 + Second; Return enddate; return date





Guess you like

Origin blog.csdn.net/weixin_44540773/article/details/90264865