JS determines whether the time format is valid [Post 11:12:14] 1 short time, such as (13:04:06)
Function Istime (STR)
{
VaR A = Str. Match (/^ (\ D {1, 2 })(:)? (\ D {1, 2}) \ 2 (\ D {1, 2}) $ /);
If (A = NULL) {alert ('input parameter is not in the timeformat '); Return false ;}
If (A [1]> 24 | A [3]> 60 | A [4]> 60)
{
Alert ("Time Format incorrect ");
Return false
}
Return true;
}
2. Short date, such)
Function strdatetime (STR)
{
VaR r = Str. match (/^ (\ D {}) (-| \/) (\ D {}) \ 2 (\ D {}) $ /);
If (r = NULL) return false;
VaR d = new date (R [1], R [3]-1, R [4]);
Return (D. getfullyear () = R [1] & (D. getmonth () + 1) = R [3] & D. getdate () = R [4]);
}
3 long time, for example (13:04:06)
Function strdatetime (STR)
{
VaR Reg =/^ (\ D {}) (-| \/) (\ D {}) \ 2 (\ D }) (\ D {1, 2}) :( \ D {1, 2}) :( \ D {1, 2}) $ /;
VaR r = Str. Match (REG );
If (r = NULL) return false;
VaR d = new date (R [1], R [3]-1, R [4], R [5], R [6], R [7]);
Return (D. getfullyear () = R [1] & (D. getmonth () + 1) = R [3] & D. getdate () = R [4] & D. gethours () = R [5] & D. getminutes () = R [6] & D. getseconds () = R [7]);
}