版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/inforstack/article/details/46516623
public static void main(String[] args) {try {DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Calendar calendar = Calendar.getInstance();calendar.setTime(new Date());calendar.add(Calendar.DATE,7);System.out.println(formatter.format(calendar.getTime()));Date createDate = formatter.parse("2015-06-25 07:07:21"); // 创建时间Date currentDate = formatter.parse("2015-06-25 07:07:22"); //当前时间System.out.println("创建时间在当前时间之前?" + createDate.before(currentDate));} catch (ParseException e) {e.printStackTrace();}