SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); //Date d = format.parse(str.replace("Z", " UTC"));//注意是空格+UTC //System.out.println(d);
Date date=new Date();
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);//获得昨天时间
System.out.println(date);
String temp=format.format(date);
String hours=format.format(calendar.getTime());
System.out.println(temp);
System.out.println(":::"+hours); int end=temp.indexOf("+");
String re=temp.substring(0,end)+"Z"; int end2=hours.indexOf("+");
String re2=hours.substring(0,end2)+"Z";
System.out.println("当前时间"+re);
System.out.println("前一小时"+re2); try {
System.out.println(format.parse(re.replace("Z", "UTC")));
} catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace();
}