简体   繁体   English

java.text.ParseException:无法解析的日期“ yyyy-MM-dd'T'HH:mm:ss.SSSZ”-SimpleDateFormat

[英]java.text.ParseException: Unparseable date “yyyy-MM-dd'T'HH:mm:ss.SSSZ” - SimpleDateFormat

I am suffering error from this code 我正在从此代码中遇到错误

 java.text.ParseException: Unparseable date: "1998-09-17T00:00:00.000+08:00" (at offset 23)

I not sure what wrong with the code 我不确定代码有什么问题

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
          Date date = null;
          try
          {
              date = sdf.parse(startdate);
          }
          catch(Exception ex)
          {
              ex.printStackTrace();
          }
          SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
          String dateStr = formatter.format(date);

  System.out.println(dateStr);

What should I do? 我该怎么办?

The timezone format is not correct. 时区格式不正确。

The Timezone should be +0800 not +08:00 . 时区应为+0800而不是+08:00

According to the samples in the Javadocs for SimpleDateFormat , you should be fine with 根据Javadocs中用于SimpleDateFormat的示例,您应该对

"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"  -> 2001-07-04T12:08:56.235-07:00

XXX is the ISO Format, that will allow the colon in the timezone. XXX是ISO格式,可以在时区中使用冒号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法解析这种日期格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ? - Why I can't parse this date format yyyy-MM-dd'T'HH:mm:ss.SSSZ? 如何从日期格式“yyyy-MM-dd'T'HH:mm:ss.SSSZ”单独获取日,年,小时,分钟? - How to get the day, year, hours, min Individually from date format “yyyy-MM-dd'T'HH:mm:ss.SSSZ”? 如何更改 TZ 格式 2022-12-08T06:07:34.780Z (yyyy-MM-dd'T'HH:mm:ss.SSSZ) 来到服务器但显示 DD/MM/YYYY - how to change T Z Format 2022-12-08T06:07:34.780Z (yyyy-MM-dd'T'HH:mm:ss.SSSZ) come to server but Display DD/MM/YYYY Android 中的日期解析 yyyy-MM-dd'T'HH:mm:ss - Date parsing yyyy-MM-dd'T'HH:mm:ss in Android 如何在yyyy-MM-dd'T'HH:mm:ss-07:00中格式化日期/时间 - How to format date/time in yyyy-MM-dd'T'HH:mm:ss-07:00 将日期字符串解析为“ yyyy-MM-dd'T'HH:mm:ss'-'hh:mm”时,小时,分钟和米的值错误 - Wrong value for hour, minutes and mills when parsing date string to “yyyy-MM-dd'T'HH:mm:ss'-'hh:mm” Android ContentProvider,带空格的URI(日期为YYYY-MM-DD HH:MM:SS) - Android ContentProvider, URI with spaced (Date in YYYY-MM-DD HH:MM:SS) 如何正确获取“ yyyy-MM-dd HH:mm:ss”格式的日期 - How get date in “yyyy-MM-dd HH:mm:ss” format properly 从“yyyy-MM-dd hh:mm:ss.SSS”解析日期和时间 -------> android中的“hh:mm aa” - Parsing Date and time from "yyyy-MM-dd hh:mm:ss.SSS" -------> "hh:mm aa" in android 2021-04-05T16:25:45.000+00:00 SimpleDateFormat 中的时间戳更改(“yyyy-MM-dd hh:mm:ss a”) - 2021-04-05T16:25:45.000+00:00 Time stamp change in SimpleDateFormat("yyyy-MM-dd hh:mm:ss a")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM