代码如下:
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");才能正常……