UTC时间格式(2021-04-27T08:03:15.085Z)格式化方法
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DataFormat {
public static void main(String[] args) {
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
try {
Date date = sdf1.parse("2021-04-27T08:03:15.085Z");
cal.setTime(date);
cal.add(Calendar.HOUR_OF_DAY,+8);//时区加8小时
date= cal.getTime();
String str = sdf2.format(date);
System.out.println(str);
} catch (ParseException e) {
e.printStackTrace();
}
}
}