public class DateTest {
public static void main(String[] args) {
/**
* 方式一:
*/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
Date now = new Date();// 当前时间
int s = 10 * 60;// 将10分钟转换为秒
calendar.setTime(now);
calendar.add(Calendar.SECOND, s);// 添加s秒
String formatTime1 = sdf.format(calendar.getTime());
System.out.println("date1:" + formatTime1);
/**
* 方式二:
*/
long currentTime = System.currentTimeMillis();// 当前时间
long requiredTime = currentTime + 10 * 60 * 1000;// 将10分钟转为毫秒
String formatTime2 = sdf.format(requiredTime);
System.out.println("date2:" + formatTime2);
}
}
运行结果为:
date1:2019-02-27 20:18:06
date2:2019-02-27 20:18:06
原文地址:https://www.cnblogs.com/qqzhulu/p/10446404.html