格式示例:2020-01-13T16:00:00.000Z
public static void main(String[] args) {
String dateTime = "2020-01-13T16:00:00.000Z";
dateTime = dateTime.replace("Z", " UTC");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
SimpleDateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date time = format.parse(dateTime);
String result = defaultFormat.format(time);
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
返回值:
2020-01-14 00:00:00
格式示例:2023-06-08T08:02:52
public static void main(String[] args) throws ParseException {
String cellNode="2023-06-08T08:02:52";
//a转为正常日期
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date datea = df.parse(cellNode);
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formatss = df2.format(datea);
System.out.println(formatss);
}
返回值:
2023-06-08 08:02:52
格式示例:2023-06-08T08:02:52.000+00:00
public static void main(String[] args) throws ParseException {
String cellNode="2023-06-08T08:02:52.000+00:00";
//a转为正常日期
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Date datea = df.parse(cellNode);
SimpleDateFormat df1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
Date date1 = df1.parse(datea.toString());
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formatss = df2.format(date1);
System.out.println(formatss);
}
返回值:
2023-06-08 16:02:52
格式示例:2021-05-14T23:30:35+08:00
public static void main(String[] args) throws ParseException {
String a = "2021-05-14T23:30:35+08:00";
LocalDateTime date = LocalDateTime.parse(a, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
String dateString = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(""+dateString);
}
返回值:
2021-05-14 23:30:35