今天遇到这样的时间格式需要进行转化
2021-11-02T05:55:14.428Z
转换代码如下
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TimeFormat {
public static void main(String[] args) throws ParseException {
//需要转换的时间
String myDateString = "2021-11-02T05:55:14.428Z";
//进行转化时区
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
Date myDate = dateFormat.parse (myDateString.replace("Z","+0000"));
//转换为年月日时分秒
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = df.format(myDate);
System.out.println(format);
}
}
最终效果