/**
* Determines whether it is a leap year.
* @ Param year
* @ Return
*/
Public Boolean isleap (INT year)
{
If (Year % 4 = 0 & amp; Year % 100! = 0) | (Year % 400 = 0 ))
Return true;
Else
Return false;
}
/**
* Determine the total number of days of a month in a year
* @ Param year
* @ Param month
* @ Return
*/
Public int getdays (INT year, int month ){
Int tianshu = 0;
Switch (month)
{
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
Tianshu = 31;
Break;
Case 4:
Case 6:
Case 9:
Case 11:
Tianshu = 30;
Break;
Case 2:
If (isleap (year) = true)
{
Tianshu = 29;
}
Else
{
Tianshu = 28;
}
Break;
}
Return tianshu;
}
/**
* Add days or months to a date ().
* @ Return new date
*/
Public static string changedate (string STR, int N ){
Simpledateformat SDF = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
Try {
Calendar Cd = calendar. getinstance ();
CD. settime (SDF. parse (STR ));
CD. Add (calendar. Date, N );// Add one day after approval
// CD. Add (calendar. Month, N );// Add a month
Return SDF. Format (CD. gettime ());
} Catch (exception e ){
Global. getinstance (). logerror (E );
Return STR;
}
}
// Add or subtract two dates ()
Public static void main (string [] ARGs ){
Try {
Simpledateformat DFS = new simpledateformat ("yyyy-mm-dd ");
Date begin = DFS. parse ("1992-08-10 ");
Date end = new date ();
Long between = (end. gettime ()-begin. gettime ()/1000;// Divide by 1000 to convert to seconds
Long day1 = between/(24*3600 );// Several days
Long hour1 = between % (24*3600)/3600;// Zero hours
Long minute1 = maid % 3600/60;// Zero minutes
Long second1 = maid % 60/60;// Zero seconds
} Catch (parseexception e ){
E. printstacktrace ();
}
}
// Enter a person's birthday to calculate the actual age
Public static int getage (string date ){
Try {
Simpledateformat DFS = new simpledateformat ("yyyy-mm-dd ");
Date begin = DFS. parse (date );
Int month = begin. getmonth () + 1;
Int day = begin. getdate ();
Date end = new date ();
Long between = (end. gettime ()-begin. gettime ()/1000;
Long day1 = between/(24*3600 );
Int age = (INT) (day1/365 );
Long nmonth = end. getmonth () + 1;
Long nday = end. getdate ();
If (nmonth <month | (nmonth = month & day <nday )){
Age --;
}
Return age;
} Catch (exception e ){
E. printstacktrace ();
Return 0;
}
}