待解决问题:我的时间是2016-08-15T16:00:00.000Z 想要展示的时间格式是yyyy-MM-DD HH:mm:ss
要实现UTC 通用标准时间到东八区时间的转换。
我们当前的时区是+8区 ,转换之后的时间应该是2016-08-16 00:00:00。
输入:String date = “2016-08-15T16:00:00.000Z”
输出:2016-08-16 00:00:00
方法实现:
public static String UTCStringtODefaultString(String UTCString) { try { if (CommonUtils.notNullAndEmpty(UTCString)) { UTCString = UTCString.replace("Z", " UTC"); SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z"); SimpleDateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = utcFormat.parse(UTCString); return defaultFormat.format(date); }else{ return null; } } catch(ParseException pe) { pe.printStackTrace(); return null; } }