// Determine whether it is a date
// Note: you cannot accurately determine the date of January 1, February in a leap year. js must be used for additional processing.
Function isdate (STR)
{
VaR patt =/^ ([1-9]) | (0 [1-9]) | (1 [012]) [-. /] (0? /D) | ([12]/d) | (3 [01]) [-. /] (19 | 20)/d {2}) | (19 | 20)/d {2 }[-. /] ([1-9]) | (0 [1-9]) | (1 [012]) [-. /] (0? /D) | ([12]/d) | (3 [01]) $ /;
Return patt. Test (STR );
}
// Return the system date and time
// Reference http://blog.csdn.net/avon520/archive/2008/06/13/2544133.aspx
Function getsystemdatetime ()
{
VaR now = new date ();
// Date
VaR yyyy = now. getfullyear (). tostring ();
VaR month = now. getmonth () + 1; // The month must be calculated with a plus of 1.
VaR Mm = month. tostring (). Length = 1? "0" + month. tostring (): month. tostring ();
VaR dd = now. getdate (). tostring (). Length = 1? "0" + now. getdate (). tostring (): Now. getdate (). tostring ();
// Time
VaR H = now. gethours (). tostring ();
VaR M = now. getminutes (). tostring ();
VaR S = now. getseconds (). tostring ();
Return mm + "/" + dd + "/" + yyyy + "" + H + ":" + M + ":" + S; //
}
// Date Calculation
// Returns the number of days of the date1-date2
// Note: the two dates are directly subtracted, And the return value is the difference in milliseconds.
Function datediff (date1, date2)
{
If (date1> date2)
Return parseint (math. Abs (date1-date2)/1000/60/60/24 );
Else
Return 0-parseint (math. Abs (date2-date1)/1000/60/60/24 );
}
// Returns the number of days of the specified year/month.
Function daysinmonth (Imonth, iyear)
{
VaR days = 0;
If (Imonth = 2)
{
If (iyear % 4 = 0 & (iyear % 100! = 0 | iyear % 400 = 0 ))
Days = 29;
Else
Days = 28;
}
Else
{
Days = 32-new date (-- Imonth, Imonth, 32). getdate ();
}
Return days;
}
// Tostringformat (formatstring)
Date. Prototype. tostringformat = function (formatstring)
{
// Date
VaR yyyy = This. getfullyear (). tostring ();
VaR M = (this. getmonth () + 1). tostring ();
VaR Mm = M. Length = 1? "0" + M: m;
VaR d = This. getdate (). tostring ();
VaR dd = D. Length = 1? "0" + D: D;
// Time
VaR H = This. gethours (). tostring ();
VaR HH = H. Length = 1? "0" + H: h;
VaR M = This. getminutes (). tostring ();
VaR Mm = M. Length = 1? "0" + M: m;
VaR S = This. getseconds (). tostring ();
VaR Ss = S. Length = 1? "0" + S: S;
Formatstring = formatstring. Replace (/YYYY/g, yyyy );
Formatstring = formatstring. Replace (/MM/g, mm );
Formatstring = formatstring. Replace (/DD/g, DD );
Formatstring = formatstring. Replace (/hh/g, HH );
Formatstring = formatstring. Replace (/MM/g, mm );
Formatstring = formatstring. Replace (/SS/g, SS );
Formatstring = formatstring. Replace (/M/G, M );
Formatstring = formatstring. Replace (/D/g, d );
Formatstring = formatstring. Replace (/h/g, h );
Formatstring = formatstring. Replace (/M/G, M );
Formatstring = formatstring. Replace (/S/g, S );
Return formatstring;
}