public static void main(String[] args) throws ParseException {
String utcTime = "2018-01-31T14:32:19Zsdfsdfsssss";
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
//设置时区UTC
df.setTimeZone(TimeZone.getTimeZone("UTC"));
//格式化,转当地时区时间
Date after = df.parse(utcTime);
System.out.println(after);
}
/**
* 本地时间转 UTC 时间字符串
*
* @param date
* @return
*/
public static String localToUtcString(Date date, String pattern) {
SimpleDateFormat sdf = getSdf(pattern);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(date);
}
/**
* UTC 时间反格式化
*
* @param date
* @param pattern
* @return
*/
public static Date utcStringToUtcDate(String date, String pattern) {
SimpleDateFormat sdf = getSdf(pattern);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date utcDate = null;
try {
utcDate = sdf.parse(date);
} catch (Exception e) {
}
return utcDate;
}
/**
* UTC 时间格式化
*
* @param date
* @return
*/
public static String utcDateToUtcString(Date date) {
SimpleDateFormat sdf = getSdf("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(date);
}
/**
* UTC 时间字符串转本地时间
*
* @param date
* @param pattern
* @return
*/
public static Date utcStringToLocalDate(String date, String pattern) {
SimpleDateFormat sdf = getSdf(pattern);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date localDate = null;
try {
localDate = sdf.parse(date);
} catch (Exception e) {
}
return localDate;
}
时间格式化及完整类
https://blog.csdn.net/Lxinccode/article/details/79414292