Home > Web Front-end > JS Tutorial > A brief discussion on JS date (Date) processing function_Basic knowledge

A brief discussion on JS date (Date) processing function_Basic knowledge

WBOY
Release: 2016-05-16 16:28:39
Original
1301 people have browsed it

Acquisition date

1.Date()

——Returns the date and time of the current day.

2. getDate()

- Returns the day of the month (1 ~ 31) from a Date object.

3. getDay()

- Returns the day of the week (0 ~ 6) from a Date object.

4. getMonth()

——Returns the month (0 ~ 11) from the Date object.

5. getFullYear()

- Returns the year as a four-digit number from a Date object.

6. getYear()

- Please use getFullYear() method instead.

7. getHours()
——Returns the hour (0 ~ 23) of the Date object.

8. getMinutes()

——Returns the minute (0 ~ 59) of the Date object.

9. getSeconds()

——Returns the number of seconds in Date object (0 ~ 59).

10. getMilliseconds()

——Returns the millisecond (0 ~ 999) of the Date object

11. getTime()

- Returns the number of milliseconds since January 1, 1970.

Set date

1. setDate()

——Set the day of the month (1 ~ 31) in the Date object.

2. setMonth()

——Set the month (0 ~ 11) in the Date object.

3. setFullYear()

——Sets the year (four digits) in the Date object.

4. setHours()

——Set the hour (0 ~ 23) in the Date object.

5. setMinutes()

——Set the minute (0 ~ 59) in the Date object.

6. setSeconds()

——Set the second in Date object (0 ~ 59).

7. setMilliseconds()

——Set the milliseconds (0 ~ 999) in the Date object.

8. setTime()

- Sets the Date object in milliseconds.

-------------------------------------------------- ---

JS Date object is used to handle date and time.
Syntax for creating Date objects:
var myDate=new Date()
Date objects automatically save the current date and time to their initial values.
There are the following 5 parameter forms:

new Date("month dd,yyyy hh:mm:ss");
new Date("month dd,yyyy");
new Date(yyyy,mth,dd,hh,mm,ss);
new Date(yyyy,mth,dd);
new Date(ms);

Note that in the last form, the parameter represents the number of milliseconds difference between the time to be created and January 1, 1970 GMT time. The meanings of various functions are as follows:

month: Indicates the month name in English, from January to December

mth: Use an integer to represent the month, from 0-11 (January to December)

dd: indicates the day of the month, from 1 to 31

yyyy: four-digit year

hh: Hour number, from 0 (midnight) to 23 (11 p.m.)

mm: Minutes, an integer from 0 to 59

ss: seconds, an integer from 0 to 59

ms: milliseconds, an integer greater than or equal to 0

For example:

new Date("January 12,2006 22:19:35");

new Date("January 12,2006");

new Date(2006,0,12,22,19,35);

new Date(2006,0,12);

new Date(1137075575000);

Date() returns the date and time of the current day.
getDate() returns the day of the month (1 ~ 31) from a Date object.
getDay() returns the day of the week (0 ~ 6) from a Date object.
getMonth() returns the month (0 ~ 11) from a Date object.
getFullYear() Returns the year as a four-digit number from a Date object.
getYear() Please use getFullYear() method instead.
getHours() returns the hours (0 ~ 23) of a Date object.
getMinutes() returns the minutes (0 ~ 59) of a Date object.
getSeconds() returns the number of seconds in a Date object (0 ~ 59).
getMilliseconds() returns the milliseconds (0 ~ 999) of the Date object.
getTime() returns the number of milliseconds since January 1, 1970.
getTimezoneOffset() Returns the difference in minutes between local time and Greenwich Mean Time (GMT).
getUTCDate() Returns the day of the month (1 ~ 31) from a Date object based on universal time.
getUTCDay() Returns the day of the week (0 ~ 6) from a Date object based on universal time.
getUTCMonth() returns the month (0 ~ 11) from a Date object based on universal time.
getUTCFulYear() Returns the four-digit year from a Date object based on universal time.
getUTCHours() returns the hour (0 ~ 23) of a Date object according to universal time.
getUTCMinutes() returns the minutes (0 ~ 59) of a Date object according to universal time.
getUTCSeconds() Returns the seconds (0 ~ 59) of a Date object according to universal time.
getUTCMilliseconds() returns the milliseconds (0 ~ 999) of a Date object according to universal time.
parse() returns the number of milliseconds from midnight on January 1, 1970 to the specified date (string).
setDate() sets the day of the month (1 ~ 31) in the Date object.
setMonth() sets the month (0 ~ 11) in the Date object.
setFullYear() Sets the year (four digits) in a Date object.
setYear() Please use setFullYear() method instead.
setHours() sets the hours (0 ~ 23) in the Date object.
setMinutes() sets the minutes (0 ~ 59) in the Date object.
setSeconds() sets the seconds (0 ~ 59) in the Date object.
setMilliseconds() sets the milliseconds (0 ~ 999) in the Date object.
setTime() sets a Date object in milliseconds.
setUTCDate() Sets the day of the month (1 ~ 31) in the Date object according to universal time.
setUTCMonth() Sets the month (0 ~ 11) in the Date object according to universal time.
setUTCFulYear() Sets the year (four digits) in a Date object according to universal time.
setUTCHours() Sets the hour (0 ~ 23) in a Date object according to universal time.
setUTCMinutes() Sets the minutes in a Date object (0 ~ 59) according to universal time.
setUTCSeconds() Sets the seconds in a Date object (0 ~ 59) according to universal time.
setUTCMilliseconds() Sets the milliseconds in a Date object (0 ~ 999) according to universal time.
toSource() returns the source code of this object.
toString() Converts a Date object to a string.
toTimeString() Converts the time portion of a Date object to a string.
toDateString() Converts the date portion of a Date object to a string.
toGMTString() Please use toUTCString() method instead.
toUTCString() Converts a Date object to a string according to universal time.
toLocaleString() Converts a Date object to a string according to the local time format.
toLocaleTimeString() Converts the time part of the Date object to a string according to the local time format.
toLocaleDateString() Converts the date part of the Date object to a string according to the local time format.
UTC() Returns the number of milliseconds between January 1, 1997 and the specified date, according to universal time.
valueOf() returns the original value of the Date object.
//var objDate=new Date([arguments list]);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template