java date 当前时间 加 5分钟
代码:
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
System.out.println("当前时间:" + sdf.format(date));
//方法一
Date afterDate = new Date(date .getTime() + 300000);
System.out.println("当前时间加5分钟:" + sdf.format(afterDate ));
//方法二
Calendar nowTime = Calendar.getInstance();
nowTime.add(Calendar.MINUTE, 5);
System.out.println("当前时间加5分钟:" + sdf.format(nowTime.getTime()));
}
运行结果:
代码: public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); System.out.println("当前时间:" + sdf.format(date)); //方法一 Date afterDate = new Date(date .getTime() + 300000); System.out.println("当前时间加5分钟:" + sdf.format(afterDate )); //方法二 Calendar nowTime = Calendar.getInstance(); nowTime.add(Calendar.MINUTE, 5); System.out.println("当前时间加5分钟:" + sdf.format(nowTime.getTime())); } 运行结果:下一篇:
用Python写一个自动聊天的代码