The following is a summary of js date functions for your reference
1. Get the current time
var date=new Date();
2. Convert the known year, month and day into date data:
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 whether the number of days difference between two dates is greater than 5:
parseInt((date-applyDate1) / (1000 * 60 * 60 * 24)) >= 5
4. Compare two times:
if (date.valueOf() > applyDate1.valueOf()) {
alert("The input date must not be less than the current date!");
} else {
alert("OK!");
}
5. Get the hours, minutes and seconds of the current time
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 addition: get the time 35 days after the fixed time (August 12, 2006)
var d = new Date("2006, 7, 12");
d.setDate(d.getDate() 35);
7. Methods of Date object
The Date object allows you to obtain the time and date relative to either Coordinated International Time (Greenwich Mean Time, now known as UTC-Universal Coordinated Time) or the operating system on which the Flash player is running. To use the methods of the Date object, you must first create an instance of the Date object.
Date objects must use Flash 5 or later player.
The methods of the Date object are not static, but apply to the individual entities specified when used.
Introduction to methods of Date object: ·
getDate | Get the current date (the day of the month) based on local time
getDay | Get the day of the week today is based on local time (0-Sunday, 1-Monday...)
getFullYear | Get the current year (four digits) based on local time
getHours | Get the current hours based on local time (24-hour format, 0-23)
getMilliseconds | Get the current number of milliseconds based on local time
getMinutes | Get the current minutes based on local time
getMonth | Get the current month based on local time (note starting from 0: 0-Jan, 1-Feb...)
getSeconds | Get the current seconds based on local time
getTime | Get the number of milliseconds since 1970.1.1 0:00 in UTC format
getTimezoneOffset | Get the offset value of the current time and UTC format (in minutes)
getUTCDate | Get the current date in UTC format (the day of this month)
getUTCDay | Get the day of the week today is in UTC format (0-Sunday, 1-Monday...)
getUTCFullYear | Get the current year in UTC format (four digits)
getUTCHours | Get the current hour in UTC format (24-hour format, 0-23)
getUTCMilliseconds | Get the current number of milliseconds in UTC format
getUTCMinutes | Get the current minutes in UTC format ·
getUTCMonth | Get the current month in UTC format (note starting from 0: 0-Jan, 1-Feb...)
getUTCSeconds | Get the current seconds in UTC format ·
getYear | Get the current abbreviated year based on local time (current year minus 1900)
setDate | Set the current date (the day of this month)
setFullYear | Set the current year (four digits)
setHours |Set the current hours (24-hour format, 0-23)
setMilliseconds | Set the current number of milliseconds
setMinutes | Set the current minutes
setMonth | Set the current month (note starting from 0: 0-Jan, 1-Feb...)
setUTCMinutes | Set the current minutes in UTC format
setUTCMonth | Set the current month in UTC format (note starting from 0: 0-Jan, 1-Feb...)
setUTCSeconds | Set the current seconds in UTC format
setYear | Set the current abbreviated year (current year minus 1900)
toString | Convert date and time values into string values in the form of "date/time"
Date.UTC | Returns the fixed time value of the specified UTC format date and time
setSeconds | Set the current seconds
setTime | Set the number of milliseconds since 1970.1.1 0:00 in UTC format
setUTCDate | Set the current date in UTC format (the day of the month)
setUTCFullYear | Set the current year in UTC format (four digits)
setUTCHours | Set the current hour in UTC format (24-hour format, 0-23)
setUTCMilliseconds | Set the current number of milliseconds in UTC format
8. Create a new Date object
Syntax:
new Date();
new Date(year [, month [, date [, hour [, minute [, second [, millisecond ]]]]]] );
Parameters:
year is an integer between 0 and 99, corresponding to the years 1900 to 1999, or a four-digit number specifying a definite year;
month is an integer between 0 (January) and 11 (December), this parameter is optional;
date is an integer between 1 and 31, this parameter is optional;
hour is an integer between 0 (0:00am) and 23 (11:00pm). This parameter is optional;
minute is an integer between 0 and 59, this parameter is optional;
second is an integer between 0 and 59, this parameter is optional;
millisecond is an integer between 0 and 999, this parameter is optional;
Note: Object. Create a new Date object.
Player support: Flash 5 or later.
Example:
The following is an example of getting the current date and time:
now = new Date();
The following is an example of creating a Date object about National Day:
national_day = new Date (49, 10, 1);
The following is an example of creating a new Date object, using the getMonth, getDate, and getFullYear methods of the Date object to obtain the time, and then outputting it in the dynamic text box.
myDate = new Date();
dateTextField = (mydate.getMonth() "/" myDate.getDate() "/" mydate.getFullYear());