<PRE class = "Java" name = "code"> Import java. Text. parseexception;
Import java. Text. simpledateformat;
Import java. util. calendar;
/**
* This class mainly verifies and filters characters.
* @ Author
*
*/
Public class stringutil {
// Convert the Date Format
Public static java. SQL. Date parsedate (string s) throws exception {
String [] STR = S. Split ("-");
If (Str. length! = 3 ){
Throw new exception ("the date format is incorrect! ");
}
Int year = integer. parseint (STR [0]);
Int month = integer. parseint (STR [1]);
Int day = integer. parseint (STR [2]);
If (Year> 9999 | year <0 ){
Throw new exception ("the date format is incorrect! ");
}
If (month <1 | month> 12 ){
Throw new exception ("the date format is incorrect! ");
}
If (day <1 | day> 31 ){
Throw new exception ("the date format is incorrect! ");
}
Return new java. SQL. date (year-1900, month-1, Day );
}
/**
* Parses a string into a date object.
* @ Param STR date string
* @ Return date object
* @ Throws parseexception
*/
Public static java. util. Date strtodate (string Str) throws parseexception {
// Specify the date format
Simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm ");
Java. util. Date = NULL;
// Parse the string into a date object
Date = format. parse (STR );
Return date;
}
/**
* Returns a date object based on the month of Mar.
* @ Param date object
* @ Return string
*/
Public static string datetostr (Java. util. Date ){
// Specify the date format
Simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
// Parse the date object to a string in the specified format
String STR = format. Format (date );
Return STR;
}
/**
* Date + integer = Date (minutes)
* @ Param DT date
* @ Param count integer
* @ Return date
*/
Public static java. SQL. Date minute_shift (Java. util. Date DT, int count)
{
Calendar Cal = calendar. getinstance ();
// Use the specified date to set the time of the calendar.
Cal. settime (DT );
// Add or subtract the specified time amount for the specified calendar field according to the calendar rule
// Calendar. Minute, used to set the sum of integers and dates. The value of calendar. minute is a clock.
Cal. Add (calendar. Minute, count );
Return new java. SQL. Date (Cal. gettimeinmillis ());
// Java. SQL. Date (Cal. gettimeinmillis (). tostring () // format the date in the format of yyyy-mm-dd by default
}
/* This shows the effect
Public static Java. util. date minute_shift (Java. util. date DT, int count)
{< br> calendar Cal = calendar. getinstance ();
// use the given date to set the time of this calendar
Cal. settime (DT);
// Based on calendar rules, add or subtract the specified time amount for the specified calendar field
// calendar. minute is used to set the sum of integers and dates in the calendar. minute is the clock
Cal. add (calendar. minute, count);
return New Java. util. date (Cal. gettimeinmillis ();
}< br> */
}< br>
& nbsp;