JS date object and get the current system time)

Source: Internet
Author: User
I. date object One object every day. Let's take a look at the date object today. You must be familiar with the date object. This special time effect should have been used in many places on the website. Let's recall the date object today.

Let's first look at his definition:

1 Dateobj = New Date ()
2 Dateobj = New Date (dateval)
3 Dateobj = New Date (year, month, date [, hours [, minutes [, seconds [, MS])
4 Where:
dateobj
Required. To assign a value Variable name of the date object.
dateval
Required. For numeric values, dateval indicates the number of milliseconds of the global standard time between the specified date and midnight on January 1, January 1, 1970. If it is a string, then dateval The rules in the parse method are parsed. The dateval parameter can also be the vt_date value returned from some ActiveX objects.
year
Required. The complete year, for example, 1976 (instead of 76 ).
month
Required. Indicates the month, which is an integer from 0 to 11 (January 1, January to January 1, December ).
date
Required. Represents the date, which is an integer from 1 to 31.
hours
Optional. If minutes is required. Represents the hour, an integer from 0 to 23 (midnight to 11 pm ).
minutes
Optional. If seconds is required. Minute, an integer from 0 to 59.
seconds
Optional. If milliseconds is required. Indicates the second, which is an integer from 0 to 59.
MS
Optional. Millisecond, an integer from 0 to 999.

DateThe object is saved in milliseconds to indicate a specific period of time. If the value of a parameter is greater than its range or is a negative number, other values stored will be adjusted accordingly. For example, if 150 seconds are specified, JScript redefines the number as 2 minutes 30 seconds.

If the number isNan, The object does not represent a specific time period. If notDateObject transmission parameter, which is initialized to the Current Time (UTC ). Assign a value to this object before it can be used.

DateThe date range that the object can represent is about January 1, 1970 years before and after January 1, 285,616.

DateTwo objects are not created.DateObject. They areParseAndUTC.

There are many methods for date objects, and they are also very simple and will not be listed here. OK, see next!

Note:

**************************************** **********************

VaR mydate = new date (2007,11, 23 );
Alert ("year =" + mydate. getyear () + "******* month =" + mydate. getmonth () + "********* day =" + mydate. getdate ());

The result after running is year = 2006 ******* month = 11 ********** day = 23.

**************************************** **********************

In this way, the display is normal. This problem occurs when the new date value is 12 months.

**************************************** **********************

VaR mydate = new date (2007,12, 23 );
Alert ("year =" + mydate. getyear () + "******* month =" + mydate. getmonth () + "********* day =" + mydate. getdate ());

The result after running is year = 2007 ******* month = 0 ********* day = 23.

**************************************** **********************

This is a strange thing. Finally, we can find that the value of month is 0 ~ The value of 12 cannot be input. The solution is to set month-1 when the value is passed, and then add 1 when the value is retrieved. I don't know who else has a better way.

Ii. Obtain the current system time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.