import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.SimpleFormatter;
public class DateUtil {
/**
* 将"2019-11-17 09:43:50"型字符串转化为Date
*
* @param str
* @return
* @throws ParseException
*/
public static Date StringToDate(String str) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = formatter.parse(str);
return date;
}
/**
* 判断某日期n天后,是否超过当前时间,超过为true,不超过为false
*
* @param date
* @param dayNum
* @return
*/
public static boolean judgethanCurrentDate(Date date, int dayNum) {
boolean isPassCurrentDate = false;
Calendar cal = Calendar.getInstance(); // 获取一个日历的实例
cal.setTime(date); //设置日历时间
cal.add(Calendar.DATE, dayNum); //在日历的天数上增加n天
Date afterDaysDate = cal.getTime();
Date currentDate = new Date();
if (afterDaysDate.after(currentDate)) {
// 超过当前日期
isPassCurrentDate = true;
}
return isPassCurrentDate;
}
}
时间工具类
最新推荐文章于 2024-10-03 08:33:02 发布
406

被折叠的 条评论
为什么被折叠?



