Java 和日期(无法解析的日期)
Java and Dates (Unparseable date)
我无法解决日期问题...我正在查看其他帖子,但 none 最终给了我结果。
我收到的日期如下AngularJS:
2019-05-04T09:00:00Z
在 Grails 中,我按以下方式处理它:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSX");
Date d = sdf.parse(parametros.volverallamar);
但是在尝试保存时我收到以下错误:
Unparseable date: "2019-05-03T09:00:00Z". Stacktrace follows:
谢谢!
您正在定义一个带毫秒的日期格式(.SSSSSSS
),但您实际输入的日期没有它们。
使用没有以下格式的格式:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
Date d = sdf.parse("2019-05-04T09:00:00Z");
如果您使用的是java 8 试试看:
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyy", Locale.ENGLISH);
LocalDate date = LocalDate.parse("2019-05-03T09:00:00Z", inputFormatter);
String formattedDate = outputFormatter.format(date);
System.out.println(formattedDate);
我无法解决日期问题...我正在查看其他帖子,但 none 最终给了我结果。
我收到的日期如下AngularJS:
2019-05-04T09:00:00Z
在 Grails 中,我按以下方式处理它:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSX");
Date d = sdf.parse(parametros.volverallamar);
但是在尝试保存时我收到以下错误:
Unparseable date: "2019-05-03T09:00:00Z". Stacktrace follows:
谢谢!
您正在定义一个带毫秒的日期格式(.SSSSSSS
),但您实际输入的日期没有它们。
使用没有以下格式的格式:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
Date d = sdf.parse("2019-05-04T09:00:00Z");
如果您使用的是java 8 试试看:
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("dd-MM-yyy", Locale.ENGLISH);
LocalDate date = LocalDate.parse("2019-05-03T09:00:00Z", inputFormatter);
String formattedDate = outputFormatter.format(date);
System.out.println(formattedDate);