// Define a time format variable
Private Static final string default_pattern = "yyyymmddhhmmss ";
/**
* Author Hao xuewu
* Returns the time string in the specified format after the date is calculated.
*
* @ Param Interval
* Days
* @ Param Pattern
* Time Format
* @ Return
*/
Public static string getdate (string interval, date starttime, string pattern ){
Calendar temp = calendar. getinstance (timezone. getdefault ());
Temp. settime (starttime );
Temp. Add (temp. Month, integer. parseint (interval ));
Simpledateformat SDF = new simpledateformat (pattern );
Return SDF. Format (temp. gettime ());
}
/**
* Author Hao xuewu
* Convert string type to date type
* @ Return
*/
Public static date str2date (string Str ){
Date d = NULL;
Simpledateformat SDF = new simpledateformat (default_pattern );
Try {
D = SDF. parse (STR + "000000 ");
} Catch (exception e ){
E. printstacktrace ();
}
Return D;
}
/**
* Author Hao xuewu
* Format the time.
* @ Return
*/
Public static date datepattern (date ){
Simpledateformat SDF = new simpledateformat (default_pattern );
Try {
String dd = SDF. Format (date );
Date = str2date (dd );
} Catch (exception e ){
E. printstacktrace ();
}
Return date;
}
/**
* Author Hao xuewu
* Convert date to the corresponding string
* @ Return
*/
Public static string date2str (date ){
Simpledateformat SDF = new simpledateformat (default_pattern );
Return SDF. Format (date );
}