/**
* 传入具体一天,返回具体日期减少一天
*
* @throws ParseException
*/
public static String subDay(String date) {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dt = null;
try {
dt = sdf.parse(date);
} catch (Exception e) {
e.printStackTrace();
}
final Calendar rightNow = Calendar.getInstance();
rightNow.setTime(dt);
rightNow.add(Calendar.DATE, -1);
final Date dt1 = rightNow.getTime();
final String reStr = sdf.format(dt1);
return reStr;
}
/**
* @param dateInMs
* 传入的时间long值
* @param days
* 天数 如 -1 +1
* @return
*/
public static String getDateByLong(long dateInMs, int days) {
final long curDateInMs = dateInMs + days * 24 * 60 * 60 * 1000;
return dateFormatter.format(new Date(curDateInMs));
}
/**
* 时间(yyyy-MM-dd HH:mm:ss):String格式转Date格式
*/
public static Date parseTimeFormattoDate(String date) {
Date time
时间格式转换(Date String)
最新推荐文章于 2023-06-06 22:46:45 发布