安卓转换时区2016-07-21T12:17:34.000Z转换成+8个小时
public static String formatDate(String date){
if (date== null||date.equals("")) {
throw new NullPointerException("date == null");
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//date = date.substring(0, date.indexOf("."));
//截取19位
date=date.length()>=19?date.substring(0,19):date.substring(0,date.length());
date=date.replace("T"," ");
//转换格林尼治时间
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date d= null;
try {
d = sdf.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//转换成格林尼治+8时间
sdf2.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
return sdf2.format(d);
}
转换前的时间2016-07-21T12:17:34.000Z
转换后的时间2016-07-21 20:17:34