JavaScript Date (date) object __java

Source: Internet
Author: User

Date objects are used to process dates and times. the JavaScript Date Object instance returns how the date and time of day is used to obtain the date of the day using the date () method. GetTime () GetTime () returns the number of milliseconds since January 1, 1970. setFullYear () How to set a specific date using setfullyear (). toUTCString () How to use toUTCString () to convert the date of day (based on UTC) to a string. Getday () How to use the Getday () and array to display weeks, not just numbers. Shows how a clock displays a clock on the page. complete Date Object reference manual

We provide a JavaScript Date object reference manual that includes all of the properties and methods available for date objects.

The manual contains a detailed description of each property and method and a related instance. Define Date

The Date object is used to process dates and times.

You can define a Date object by using the New keyword. The following code defines a Date object named MyDate:

var mydate=new Date ()

Note: A Date object automatically uses the current date and time as its initial value. Operation Date

By using a method for date objects, we can easily manipulate dates.

In the following example, we set a specific date for the Date object (August 9, 2008):

var mydate=new Date ()
mydate.setfullyear (2008,7,9)

Note: The parameters that represent the month are between 0 and 11. In other words, if you want to set the month to August, the argument should be 7.

In the following example, we set the Date object to the date after 5 days:

var mydate=new Date ()
mydate.setdate (Mydate.getdate () +5)

Note: If increasing the number of days changes the month or year, the date object automatically completes the conversion. Compare Date

Date objects can also be used to compare two dates.

The following code compares the current date with the August 9, 2008:

var mydate=new Date ();
Mydate.setfullyear (2008,8,9);

var today = new Date ();

if (mydate>today)
{
alert ("Today is before 9th August 2008");
}
else
{
alert ("Today was after 9th August 2008");
}

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.