Gson java.text.ParseException:无法解析的日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7816586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:32:48  来源:igfitidea点击:

Gson java.text.ParseException: Unparseable date

javagson

提问by LuxuryMode

I'm getting an exception using Gson to deserialize json.

我在使用 Gson 反序列化 json 时遇到异常。

java.text.ParseException: Unparseable date: "2011-10-19T23:30:00-04:00"

The 23:30:00 part does seem strange to me. Is this an invalid date?

23:30:00 部分对我来说似乎很奇怪。这是一个无效的日期吗?

回答by aram.salinas

You have to define the date Format in the GsonBuilder, something like this.

您必须在 GsonBuilder 中定义日期格式,就像这样。

Gson gSon=  new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();

Regards!

问候!