* 計算指定日期的上一天
*
* @param dateTime
* 日期
* @return
*/
public static String getBeforeDay(String dateTime) {
Calendar now = Calendar
SimpleDateFormat simpledate = new SimpleDateFormat(
Date date = null;
try {
date = simpledate
} catch (ParseException ex) {
System
return null;
}
now
int year = now
int month = now
int day = now
now
String time = simpledate
return time;
}
/**
* 計算指定日期的下一天
*
* @param dateTime
* 日期
* @return
*/
public static String getNextDay(String dateTime) {
Calendar now = Calendar
SimpleDateFormat simpledate = new SimpleDateFormat(
Date date = null;
try {
date = simpledate
} catch (ParseException ex) {
System
return null;
}
now
int year = now
int month = now
int day = now
now
String time = simpledate
return time;
}
/**
* 得到指定月的天數
* @param _year
* @param _month
* @return
*/
public static int getMaxDayOfMonth(int _year
Calendar now = Calendar
int year =
int month =
if(_month==
year = _year
month =
}else{
year = _year;
month = _month
}
now
now
return now
}
/**
* 計算時間差
*
* @param beginTime
* 開始時間
* @param endTime
* 結束時間
* @return 從開始時間到結束時間之間的時間差(秒)
*/
public static long getTimeDifference(String beginTime
long between =
SimpleDateFormat sdf = new SimpleDateFormat(
Date end = null;
Date begin = null;
try {// 將截取到的時間字符串轉化為時間格式的字符串
end = sdf
begin = sdf
} catch (ParseException e) {
e
}
between = (end
return between;
}
/**
* 計算時間差
*
* @param time
* 指定的時間
* @return 當前時間和指定時間的時間差(秒)
*/
public static long getTimeDifference(String time) {
long between =
SimpleDateFormat sdf = new SimpleDateFormat(
String systemTime = sdf
Date end = null;
Date begin = null;
try {// 將截取到的時間字符串轉化為時間格式的字符串
end = sdf
begin = sdf
} catch (ParseException e) {
e
}
between = Math
return between;
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25543.html