java android格林威治时间转成本地时间

private String GTMToLocal(String GTMDate) {


int tIndex = GTMDate.indexOf("T");
String dateTemp = GTMDate.substring(0, tIndex);
String timeTemp = GTMDate.substring(tIndex + 1, GTMDate.length() - 6);
String convertString = dateTemp + " " + timeTemp;


SimpleDateFormat format;
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
Date result_date;
long result_time = 0;


if (null == GTMDate) {
return GTMDate;
} else {
try {
format.setTimeZone(TimeZone.getTimeZone("GMT00:00"));
result_date = format.parse(convertString);
result_time = result_date.getTime();
format.setTimeZone(TimeZone.getDefault());
return format.format(result_time);
} catch (Exception e) {
e.printStackTrace();
}
}
return GTMDate;


}

你可能感兴趣的:(android初级)