- /* Parses string type into date type.
-
- Parsedate ('1970-1-1 ') return new date (2006, 1)
-
- Parsedate ('2006-1-1 ') return new date (, 1)
-
- Parsedate ('1970-1-1 15:14:16 ') return new date (2006)
-
- Parsedate ('2006-1-1 15:14:16 ') return new date );
-
- Parsedate ('1970-1-1 15:14:16. 123') return new date (2006, 254, 254)
- Parsedate ('2006-1-1 15:14:16. 100') return new date (254, 254)
-
- Parsedate ('incorrect format') retrun null
-
- */
-
- FunctionParsedate (STR ){
-
- If(TypeofSTR ='String'){
- VaRResults = Str. Match (/^ * (\ D {4})-(\ D {1, 2})-(\ D {1, 2}) * $ /);
-
- If(Results & results. length> 3)
-
- Return NewDate (parseint (results [1]), parseint (results [2])-1, parseint (results [3]);
-
- Results = Str. match (/^ * (\ D {4})-(\ D {1, 2})-(\ D {1, 2}) + (\ D {1, 2 }) :( \ D {1, 2}) :( \ D {1, 2}) * $ /);
- If(Results & results. length> 6)
-
- Return NewDate (parseint (results [1]), parseint (results [2])-1, parseint (results [3]), parseint (results [4]), parseint (results [5]), parseint (results [6]);
-
- Results = Str. match (/^ * (\ D {4})-(\ D {1, 2})-(\ D {1, 2}) + (\ D {1, 2 }) :( \ D {1, 2}) :( \ D {1, 2 })\. (\ D {1, 9}) * $ /);
-
- If(Results & results. length> 7)
- Return NewDate (parseint (results [1]), parseint (results [2])-1, parseint (results [3]), parseint (results [4]), parseint (results [5]), parseint (results [6]), parseint (results [7]);
-
- }
-
- Return Null;
-
- }
-
-
- /*
-
- Parses the date/string type into the string type.
- If the string type is input, it is first parsed as the date type
-
- Incorrect date. ''is returned''
-
- If the time part is 0, only the date part is returned.
-
- */
-
- FunctionFormatdate (v ){
-
- If(TypeofV ='String') V = parsedate (v );
- If(VInstanceofDate ){
-
- VaRY = V. getfullyear ();
-
- VaRM = V. getmonth () + 1;
-
- VaRD = V. getdate ();
-
- VaRH = V. gethours ();
- VaRI = V. getminutes ();
-
- VaRS = V. getseconds ();
-
- VaRMS = V. getmilliseconds ();
- If (MS> 0) return Y + '-' + M + '-' + D + '' + H + ': ' + I + ': ' + S + '. ' + MS;
- If(H> 0 | I> 0 | S> 0)ReturnY +'-'+ M +'-'+ D +''+ H +':'+ I +':'+ S;
-
- ReturnY +'-'+ M +'-'+ D;
-
- }
- Return '';
-
- }
Http://lihui5028.iteye.com/blog/376095