JavaScript Date Object

Source: Internet
Author: User
Tags date1

Create a Date object:
var objdate=new Date ([arguments list]);

The parameters are of the following types:
New Date ("2012/11/22 [18:35:00]");
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);

You need to be aware of the last form, which represents the number of milliseconds between the time that you need to create and the GMT time of January 1, 1970. The meanings of the various functions are as follows:

Month: The name of the months in English, from January to December

MTH: The month is expressed in integers, from 0 (January) to 11 (December)

DD: Represents the day ordinal of one months, from 1 to 31

YYYY: four-digit year

HH: Hours, from 0 (midnight) to 23 (11 o'clock in the evening)

MM: Number of minutes, integers from 0 to 59

SS: Number of seconds, integers from 0 to 59

MS: Number of milliseconds, integer greater than or equal to 0

Such as:

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);

The various forms of creation above represent the day of January 12, 2006.

extracting information from a Date object
var objdate=new Date ();

Objdate.getfullyear () returns the year in four digits
Objdate.getyear () returns the year in two-bit or four-digit numbers depending on the browser
Objdate.getmonth ()
Objdate.getdate ()
Objdate.getday ()
Objdate.gethours ()
Objdate.getmilliseconds ().
..........

1. Each component has a pair of child get/set methods;

2. Name of the method: month, day and week without s

Each millisecond ends with s;

Such as:

Set Hour: sethours ()

Set Month: GetMonth ()

Special:

Year: Get/setfullyear ()-Use 4-bit full year;

Week: GetDay (): Get the serial number of the week;

The day one ... Six

0 1 6

No set method for the week;

Day of the Month: Get/setdate ();

3. Return value:

Day of the month: 1-31;

The other components are from 0 to 1 end;

Month: minus 1 compared to normal;

How to calculate the Date: 2 kinds;

1. Two date object is directly subtracted, the result is millisecond difference!

2. Add and subtract any component:

Get out first.

Do the calculations

Then put it back with set;

3.set (Get () + calculation);

4. Date-to-string output:

1.date.tolocalestring ();

2.date.tolocaledatestring ();

2.date.tolocaletimestring ();

Copy Date Object

var date1=new Date ();

var date2=new Date (Date1.gettime ());

Date2.set (Date2.get () + calculation);

JavaScript Date Object

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.