你们服务器返回的时间格式是UTC 请问怎样转换为 yyyy.MM.dd HH:mm:ss格式的时间 ,我转换出时间总对不上,我用的java
我的代码:
public static String utc2Local(String utcTime, String utcTimePatten,
String localTimePatten) {
SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);
utcFormater.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gpsUTCDate = null;
try {
gpsUTCDate = utcFormater.parse(utcTime);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);
localFormater.setTimeZone(TimeZone.getDefault());
String localTime = localFormater.format(gpsUTCDate.getTime());
return localTime;
}
调用:
String newTime = utc2Local(time,"yyyy-MM-dd'T'HH:mm:ss.mmm'Z'","yyyy.MM.dd HH:mm:ss");
@sdjcw