JavaScript Time Function Encyclopedia _ Basics

Source: Internet
Author: User
Tags getdate local time time and date

The following is a summary of the JS date function encyclopedia, for your reference

1. Get the current time

Copy Code code as follows:
var date=new date ();

2. Date-converted data of the year, month and day known:

Copy Code code as follows:

var applydate = Document.domainExceptionForm.applyDate.value;
Applydate = Applydate.split ("T") [0];
var applyyear = Applydate.split ("-") [0];
var applymonth = Applydate.split ("-") [1]-1;
var applyday = Applydate.split ("-") [2];
var applyDate1 = new Date (applyyear, Applymonth, Applyday);

3. Compare two dates with a difference of more than 5 days:

Copy Code code as follows:

parseint (date-applydate1)/(1000 *) >= 5

4. Compare two times:

Copy Code code as follows:

if (date.valueof () > Applydate1.valueof ()) {
Alert ("Enter a date that must not be less than the current date!") ");
} else {
Alert ("ok!");
}

5. Time seconds to get current

Copy Code code as follows:

var tody = new Date ();
var Nian = Tody.getfullyear ();
var youe = tody.getmonth () + 1;
var day = Tody.getdate ();
var hour = tody.gethours ();
var min = tody.getminutes ();
var Miao = tody.getseconds ();

6. Time added: To obtain a fixed time (August 12, 2006) 35 days after the time

Copy Code code as follows:

var d = new Date ("2006,7,12");
D.setdate (D.getdate () + 35);

Methods of 7.Date objects

The Date object enables you to obtain the time and date of the operating system relative to the International Standard Time (Greenwich Mean Time, now known as utc-universal coordinated times) or the Flash player 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 a Date object is not static, but it can be applied to a separate entity that is specified when used.
Introduction to Methods for Date objects: ·

Copy Code code as follows:
getDate | Get current date based on local time (date of this month)
Getday | Based on local time get today is the day of the week (0-sunday,1-monday ...)
getFullYear | Get current year (four digits) based on local time
getHours | Gets the current number of hours based on local time (24-hour system, 0-23)
getmilliseconds | Get the current number of milliseconds based on local time
getminutes | Get the current number of minutes based on local time
getmonth | Get the current month based on local time (note starting at 0:0-jan,1-feb ...)
getseconds | Get the current number of seconds based on local time
GetTime | Get the number of milliseconds since 1970.1.1 0:00 in UTC format
getTimezoneOffset | Get offset values (in minutes) for the current time and UTC format
getUTCDate | Get current date in UTC format (date of this month)
getUTCDay | Get the UTC format today is the day of the week (0-sunday,1-monday ...)
getUTCFullYear | Get current year in UTC format (four digits)
getUTCHours | Get the current number of hours in UTC (24 hours, 0-23)
getUTCMilliseconds | Get current number of milliseconds in UTC format
getUTCMinutes | Get the current number of minutes in UTC ·
getUTCMonth | Get the current month in UTC format (note starting at 0:0-jan,1-feb ...)
getUTCSeconds | Get the current number of seconds in UTC ·
getyear | Get current abbreviated year based on local time (current year minus 1900)
setdate | Set the current date (number of this month)
setFullYear | Set current year (four digits)
sethours | Set the current number of hours (24 hours, 0-23)
setmilliseconds | Set the current number of milliseconds
setminutes | Set the current number of minutes
setmonth | Set the current month (note starting at 0:0-jan,1-feb ...)
setUTCMinutes | Set the current number of minutes in UTC format
setUTCMonth | Set the current month in UTC format (note starting at 0:0-jan,1-feb ...)
setUTCSeconds | Set the current number of seconds in UTC format
Setyear | Set the current abbreviation year (minus 1900 for the current year)
ToString | Converts a date-time value to a string value in the form of date/time
DATE.UTC | Returns a fixed time value for the specified UTC format date time
setseconds | Set the current number of seconds
settime | Set the number of milliseconds since 1970.1.1 0:00 in UTC format
setUTCDate | Set the current date in UTC format (date of this month)
setUTCFullYear | Set the current year in UTC format (four digits)
setutchours | Set the current number of hours in UTC format (24 hours, 0-23)
setUTCMilliseconds | Set the current number of milliseconds in UTC format

8. Create a new Date object

Grammar:

Copy Code code as follows:

New Date ();

New Date (year [, Month [, date [, hour [, minute [, second [, millisecond]]];

Parameters:

Copy Code code as follows:

Year is an integer between 0 and 99, corresponding to 1900-1999, or specifying a certain age for four digits;
Month is an integer between 0 (January) to 11 (December), which is optional;
Date is an integer between 1 and 31, which is optional;
Hour is an integer between 0 (0:00am) to (11:00pm), which is optional;
The minute is an integer between 0 and 59, which is optional;
The second is an integer between 0 and 59, which is optional;
The millisecond is an integer between 0 and 999, which is optional;

Comments: Objects. Creates a new Date object.
Player support: Flash 5 or later version.
Example:

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

Copy Code code as follows:
now = new Date ();

The following is an example of a Date object on National day:

Copy Code code as follows:
National_day = new Date (49, 10, 1);

The following is an example of a new Date object that uses the GetMonth, GetDate, and getFullYear methods of the Date object to get time and then output in a dynamic text box.

Copy Code code as follows:

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

Related Article

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.