The date method in JS

Source: Internet
Author: User
Tags time and date

Date (object)

The Date object enables you to get time and date relative to the International Standard Time (Greenwich Mean Time, now known as utc-universal coordinated times) or the operating system that the Flash player is running. To use the method of the Date object, you must first create an entity (Instance) of the Date object.

The Date object must use the Flash 5 or later version of the player.

The method of the Date object is not static, but can be applied to the individual entity specified when it is used.

Introduction to Methods for Date objects:

getdate | Gets the current date based on local time (the number of this month)

Getday | Get today is the day of the week based on local time (0-sunday,1-monday ...)

getFullYear | Gets the current year (four digits) based on local time

gethours | Gets the current number of hours based on local time (24-hour, 0-23)

getmilliseconds | Gets the current number of milliseconds based on local time

getminutes | Gets the current number of minutes based on local time

getmonth | Gets the current month based on local time (note starting from 0:0-jan,1-feb ...)

getseconds | Gets the current number of seconds based on local time

gettime | Gets the number of milliseconds since 1970.1.1 0:00 in UTC format

getTimezoneOffset | Gets the offset value (in minutes) for the current time and UTC format

getutcdate | Gets the current date in UTC format (the number of this month)

getUTCDay | Gets the day of the week in UTC format (0-sunday,1-monday ...)

getUTCFullYear | Gets the current year in UTC format (four digits)

getutchours | Gets the current number of hours in UTC format (24-hour, 0-23)

getUTCMilliseconds | Gets the current number of milliseconds in UTC format

getUTCMinutes | Gets the current number of minutes in UTC format

getUTCMonth | Gets the current month in UTC format (note starting from 0:0-jan,1-feb ...)

getUTCSeconds | Gets the current number of seconds in UTC format

getyear | Gets the current abbreviated year based on local time (current year minus 1900)

setdate | Set the current date (the number of this month)

setFullYear | Setting the current year (four digits)

sethours | Set current hours (24-hour, 0-23)

Setmilliseconds | Set the current number of milliseconds

setminutes | Set the current number of minutes

Setmonth | Set the current month (note starting from 0:0-jan,1-feb ...)

setseconds | Set the current number of seconds

SetTime | Sets the number of milliseconds since 1970.1.1 0:00 in UTC format

setUTCDate | Set the current date in UTC format (the number of this month)

setUTCFullYear | Set the current year (four digits) in UTC format

setUTCHours | Set the current number of hours in UTC (24-hour, 0-23)

setUTCMilliseconds | Set the current number of milliseconds in UTC format

setUTCMinutes | Set the current number of minutes in UTC format

setUTCMonth | Set the current month in UTC format (note starting from 0:0-jan,1-feb ...)

setUTCSeconds | Set the current number of seconds in UTC format

Setyear | Set the current abbreviation year (current year minus 1900)

ToString | Converts a datetime value to a string value in the form "Date/Time"

· DATE.UTC | Returns a fixed-time value for the specified UTC format date time

To create a new Date object

Grammar:

New Date ();

New Date (year [, Month [, Date [, Hour [, minute [, second [, millisecond]]]]);

Parameters:

Year is an integer between 0 and 99, which corresponds to 1900-1999, or a specified number of years for four digits;

Month is an integer between 0 (January) and 11 (December), and this parameter is optional;

Date is an integer between 1 and 31, and this parameter is optional;

Hour is an integer between 0 (0:00am) to 11:00pm, and this parameter is optional;

Minute is an integer between 0 and 59, and this parameter is optional;

Second is an integer between 0 and 59, and this parameter is optional;

Millisecond is an integer between 0 and 999, and this parameter is optional;

Comments:

Object. Creates a new Date object.

Player Support:

Flash 5 or later version.

Example:

Here is an example of getting the current date and time:

now = new Date ();

Here is an example of a Date object on National Day:

National_day = new Date (49, 10, 1);

The following is an example of a new Date object that takes time with the GetMonth, GetDate, and getFullYear methods of the Date object and then outputs it in a dynamic text box.

MyDate = new Date ();

Datetextfield = (Mydate.getmonth () + "/" + mydate.getdate () + "/" + mydate.getfullyear ());

Date > Date.getdate

Date.getdate

Syntax: Mydate.getdate ();

Parameters: None

Comments:

Method. Gets the current date (the number of this month) based on local time, and the return value is an integer from 1 to 31.

Player support: Flash 5 or later version.

Date > Date.getday

Date.getday

Syntax: Mydate.getday ();

Parameters: None

Comments:

Method. Based on local time gets today is the day of the week (0-Sunday, 1-Monday ...). Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.getfullyear

Date.getfullyear

Syntax: Mydate.getfullyear ();

Parameters: None

Comments:

Method. Gets the current year (four digits, for example, 2000) based on local time. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Example:

The following example creates a new Date object and then outputs the year obtained by the getFullYear method in the Output window:

MyDate = new Date ();

Trace (Mydate.getfullyear ());

Date > Date.gethours

Date.gethours

Syntax: Mydate.gethours ();

Parameters: None

Comments:

Method. Gets the current hour based on local time (24-hour system with an integer that returns a value of 0-23). Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.getmilliseconds

Date.getmilliseconds

Syntax: Mydate.getmilliseconds ();

Parameters: None

Comments:

Method. Gets the current number of milliseconds based on local time (the return value is an integer from 0 to 999). Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.getminutes

Date.getminutes

Syntax: Mydate.getminutes ();

Parameters: None

Comments:

Method. Gets the current number of minutes based on local time (the return value is an integer from 0 to 59). Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.getmonth

Date.getmonth

Syntax: Mydate.getmonth ();

Parameters: None

Comments:

Method. Gets the current month based on local time (note starting from 0:0-1 months, 1-2 months ...). Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.getseconds

Date.getseconds

Syntax: Mydate.getseconds ();

Parameters: None

Comments:

Method. Gets the current number of seconds based on local time (the return value is an integer from 0 to 59). Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.gettime

Date.gettime

Syntax: Mydate.gettime ();

Parameters: None

Comments:

Method. Returns the number of milliseconds from January 1, 1970 0:00am to the present in UTC format. Use this method to describe the time of the same instant in the same region.

Player support: Flash 5 or later version.

Date > Date.gettimezoneoffset

Date.gettimezoneoffset

Syntax: Mydate.gettimezoneoffset ();

Parameters: None

Comments:

Method. Gets the offset value (in minutes) for the current time and UTC format.

Player support: Flash 5 or later version.

Example:

The following example returns the offset value between the time of day and UTC.

New Date (). getTimezoneOffset ();

The results are as follows:

480 (8 hours * 60 minutes/hour = 480 minutes)

Date > Date.getutcdate

Date.getutcdate

Syntax: Mydate.getutcdate ();

Parameters: None

Comments:

Method. Gets the current date in UTC format (the number of this month).

Player support: Flash 5 or later version.

Date > Date.getutcday

Date.getutcday

Syntax: Mydate.getutcdate ();

Parameters: None

Comments:

Method. Get the UTC format today is the day of the week (0-Sunday, 1-Monday ...).

Player support: Flash 5 or later version.

Date > Date.getutcfullyear

Date.getutcfullyear

Syntax: Mydate.getutcfullyear ();

Parameters: None

Comments:

Method. Gets the current year in UTC format (four digits).

Player support: Flash 5 or later version.

Date > Date.getutchours

Date.getutchours

Syntax: Mydate.getutchours ();

Parameters: None

Comments:

Method. Gets the current number of hours in UTC format (a 24-hour system with a return value of 0-23 for an integer).

Player support: Flash 5 or later version.

Date > Date.getutcmilliseconds

Date.getutcmilliseconds

Syntax: Mydate.getutcmilliseconds ();

Parameters: None

Comments:

Method. Gets the current number of milliseconds in UTC format (The return value is an integer from 0 to 999).

Player support: Flash 5 or later version.

Date > Date.getutcminutes

Date.getutcminutes

Syntax: Mydate.getutcminutes ();

Parameters: None

Comments:

Method. Gets the current number of minutes in UTC format (The return value is an integer from 0 to 59).

Player support: Flash 5 or later version.

Date > Date.getutcmonth

Date.getutcmonth

Syntax: Mydate.getutcmonth ();

Parameters: None

Comments:

Method. Gets the current month in UTC format (note starting from 0:0-1 months, 1-2 months ...).

Player support: Flash 5 or later version.

Date > Date.getutcseconds

Date.getutcseconds

Syntax: Mydate.getutcseconds ();

Parameters: None

Comments:

Method. Gets the current number of seconds in UTC format (The return value is an integer from 0 to 59).

Player support: Flash 5 or later version.

Date > Date.getyear

Date.getyear

Syntax: Mydate.getyear ();

Parameters: None

Comments:

Method. Gets the current abbreviated year (current year minus 1900) based on local time. Local time is determined by the operating system that the Flash player is running. For example 2000 is expressed in 100来.

Player support: Flash 5 or later version.

Date > Date.setdate

Date.setdate

Syntax: mydate.setdate (date);

Parameter: Date is an integer between 1 and 31.

Comments:

Method. Sets the current date (the number of this month) based on local time. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.setfullyear

Date.setfullyear

Syntax: Mydate.setfullyear (year [, Month [, Date]]);

Parameters:

The four-bit integer specified in year represents the specified years, and the two-digit number does not represent the year, such as 99 does not represent 1999, only the A.D. 99

Month is an integer from 0 (January) to 11 (December), and this parameter is optional.

Date is an integer from 1 to 31, and this parameter is optional.

Comments:

Method. Sets the year based on local time. If you set the month and date parameters, both the month and the date are set. Local time is determined by the operating system that the Flash player is running. After setting, the values obtained by the GetUTCDay and GetDay methods will change accordingly.

Player support: Flash 5 or later version.

Date > Date.sethours

Date.sethours

Syntax: Mydate.sethours (hour);

Parameter: Hour is an integer from 0 (0:00am) to (11:00pm).

Comments:

Method. Sets the current number of hours based on local time. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.setmilliseconds

Date.setmilliseconds

Syntax: Mydate.setmilliseconds (millisecond);

Parameter: Millisecond is an integer from 0 to 999.

Comments:

Method. Sets the current number of milliseconds based on local time. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.setminutes

Date.setminutes

Syntax: Mydate.setminutes (minute);

Parameter: Minute is an integer from 0 to 59.

Comments:

Method. Sets the current number of minutes based on local time. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.setmonth

Date.setmonth

Syntax: Mydate.setmonth (month [, Date]);

Parameters:

Month is an integer from 0 (January) to 11 (December)

Date is an integer from 1 to 31, and this parameter is optional.

Comments:

Method. Sets the current number of months based on local time, and if the date parameter is selected, the dates are set simultaneously. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.setseconds

Date.setseconds

Syntax: Mydate.setseconds (second);

Parameter: Second is an integer from 0 to 59.

Comments:

Method. Sets the current number of seconds based on local time. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.settime

Date.settime

Syntax: Mydate.settime (millisecond);

Parameter: Millisecond is an integer from 0 to 999.

Comments:

Method. Sets the specified date by the number of milliseconds.

Player support: Flash 5 or later version.

Date > Date.setutcdate

Date.setutcdate

Syntax: mydate.setutcdate (date);

Parameter: Date is an integer from 1 to 31.

Comments:

Method. When you set the date in UTC, using this method will not affect the value of the other fields of the Date object, but the GetUTCDay and GetDay methods return the new value after the date change.

Player support: Flash 5 or later version.

Date > Date.setutcfullyear

Date.setutcfullyear

Syntax: Mydate.setutcfullyear (year [, Month [, Date]]);

Parameters:

Year represents a four-bit integer for the years, such as 2000

Month an integer from 0 (January) to 11 (December), optional parameter.

Date a whole number from 1 to 31, optional parameter.

Comments:

Method. Sets the year in UTC, and also sets the month and date if an optional parameter is used. After setting the GetUTCDay and GetDay methods return a corresponding new value.

Player support: Flash 5 or later version.

Date > Date.setutchours

Date.setutchours

Syntax: Mydate.setutchours (hour [, minute [, second [, millisecond]]));

Parameters:

Hour is an integer from 0 (0:00am) to (11:00pm).

Minute is an integer from 0 to 59, an optional parameter.

Second is an integer from 0 to 59, an optional parameter.

Millisecond is an integer from 0 to 999, an optional parameter.

Comments:

Method. Sets the number of hours in UTC, and sets the minute, second, and millisecond values if an optional parameter is used.

Player support: Flash 5 or later version.

Date > Date.setutcmilliseconds

Date.setutcmilliseconds

Syntax: Mydate.setutcmilliseconds (millisecond);

Parameter: Millisecond is an integer from 0 to 999.

Comments:

Method. Sets the number of milliseconds in UTC format.

Player support: Flash 5 or later version.

Date > Date.setutcminutes

Date.setutcminutes

Syntax: Mydate.setutcminutes (minute [, second [, millisecond]]);

Parameters:

Minute is an integer from 0 to 59, an optional parameter.

Second is an integer from 0 to 59, an optional parameter.

Millisecond is an integer from 0 to 999, an optional parameter.

Comments:

Method. Sets the number of minutes in UTC format, and sets the second and millisecond values if an optional parameter is used.

Player support: Flash 5 or later version.

Date > Date.setutcmonth

Date.setutcmonth

Syntax: Mydate.setutcmonth (month [, Date]);

Parameters:

Month is an integer from 0 (January) to 11 (December)

Date is an integer from 1 to 31, and this parameter is optional.

Comments:

Method. Set the month in UTC format, and optionally set the date. After setting the GetUTCDay and GetDay methods, the corresponding new values are returned.

Player support: Flash 5 or later version.

Date > Date.setutcseconds

Date.setutcseconds

Syntax: Mydate.setutcseconds (second [, millisecond]));

Parameters:

Second is an integer from 0 to 59, an optional parameter.

Millisecond is an integer from 0 to 999, an optional parameter.

Comments:

Method. Sets the number of seconds in UTC format, and sets the millisecond value if an optional parameter is used.

Player support: Flash 5 or later version.

Date > Date.setyear

Date.setyear

Syntax: Mydate.setyear (year);

Parameter: Year is a four-bit integer that represents the years, such as 2000.

Comments:

Method. Sets the year based on local time. Local time is determined by the operating system that the Flash player is running.

Player support: Flash 5 or later version.

Date > Date.tostring

Date.tostring

Syntax: mydate.tostring ();

Parameters: None

Comments:

Method. Convert datetime values to string values in Date/time form

Player support: Flash 5 or later version.

Example:

The following example outputs the National_day object of the national day as a readable string:

var national_day = Newdate (49, 9, 1, 10, 00);

Trace (national_day.tostring ());

Output (for Pacific Standard Time):

Results: Sat Oct 1 10:00:00 gmt+0800 1949

Date > DATE.UTC

Date.utc

Syntax: DATE.UTC (year, month [, Date [, Hour [, minute [, second [, millisecond]]]);

Parameters:

Year represents a four-bit integer for the years, such as 2000

Month is an integer from 0 (January) to 11 (December).

Date a whole number from 1 to 31, optional parameter.

Hour is an integer from 0 (0:00am) to (11:00pm).

Minute is an integer from 0 to 59, an optional parameter.

Second is an integer from 0 to 59, an optional parameter.

Millisecond is an integer from 0 to 999, an optional parameter.

Comments:

Method. Returns the number of milliseconds 0:00am the specified time from January 1, 1970. This is a static method and does not require a specific object. It is able to create a new Date object in UTC format, and new date () creates a Date object of local time.

Player support: Flash 5 or later version.

JS get UTC Time:

var bt=new Date ();

var date=new date (Bt.getutcfullyear (), Bt.getutcmonth (), Bt.getutcdate (), bt.getutchours (), Bt.getutcminutes (), Bt.getutcseconds (), bt.getutcmilliseconds ());

Console.log (Bt.getutcfullyear () + ", Month" +bt.getutcmonth () + ", Day" +bt.getutcdate () + ", when" +bt.getutchours () + ", min" + Bt.getutcminutes () + ", Seconds" +bt.getutcseconds () + ", microseconds" +bt.getutcmilliseconds () + "-----" +date.getfullyear () + ", month" + Date.getmonth () + ", Day" +date.getdate () + ", when" +date.gethours () + ", Minutes" +date.getminutes () + ", Seconds" +date.getseconds () + ", microseconds" + Date.getmilliseconds ());

Console.log ("Time=" +bt.gettime () + ", date=" +date.gettime ());

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.