java获取当前时间加半小时之后的时间

代码如下:
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
TimeZone timeZoneChina = TimeZone.getTimeZone("Asia/Shanghai");//获取中国的时区
sdf.setTimeZone(timeZoneChina);
String time = sdf.format( now );
Date dt = sdf.parse(time);
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(dt);
rightNow.add(Calendar.HOUR_OF_DAY,1);//时间减半小时
Date dt1 = rightNow.getTime();
String reStr = sdf.format(dt1);
return reStr;
如何修改?最好能简化一下代码,而且获取系统时间比准确时间少8小时,加了代码TimeZone timeZoneChina = TimeZone.getTimeZone("Asia/Shanghai");才能正常……

第1个回答  2017-12-04
java获取当前时间加半小时之后的时间:
SimpleDateFormat FORMAT2 = new SimpleDateFormat("HH:mm:ss");
第2个回答  2017-11-13
public class testDate {
public static void main(String[] args) {
Calendar now = Calendar.getInstance();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
System.out.println(sdf.format(now.getTime()));
now.add(Calendar.MINUTE, 30);
System.out.println(sdf.format(now.getTime()));
}
}
第3个回答  2019-03-20
TimeUnit.MINITE.sleep(30);
return new Data();
第4个回答  2018-12-11
还yV🔥公
相似回答