錯誤的寫法:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //這里的格式也可以是別的 createAt =format.parse(y.getCreatedAt()); //此處是接收到的 2019-09-27T18:31:31+08:00
正確的寫法:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"); reateAt = format.parse(y.getCreatedAt()); // 此處是接收到的 2019-09-27T18:31:31+08:00
要用 "yyyy-MM-dd'T'HH:mm:ssX" 這樣的格式才能解析, 在國內的論壇幾乎搜不到 T 這樣的日期格式博客文章,國內的技術分享精神還是不成熟呀, 在國外網站找到了解決方法,
特寫此篇博客,幫后來者節省解決此類問題的時間,貼上國外博客地址:https://stackoverflow.com/questions/7681782/simpledateformat-unparseable-date-exception