至今字符串(无效格式) [英] String to date (Invalid format)

查看:97
本文介绍了至今字符串(无效格式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Joda-Time 库将我的String日期转换为真实日期,因为这似乎是最简单的解决方案。我正在使用 DateTime 对象;

I am using Joda-Time library to convert my String dates to a real date, because this seemed like the easiest solution to do this. I am using the DateTime object to do this;

 new DateTime(strValue);

但是在插入某些格式时会抛出异常;

But when inserting some formats it throws me the exception;

java.lang.IllegalArgumentException: Invalid format: "Mon, 30 Sep 2002 01:56:02 GMT"
java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 19:59:01 GMT"
java.lang.IllegalArgumentException: Invalid format: "Mon, 30 Sep 2002 01:52:02 GMT"
java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 17:05:20 GMT"
java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 19:09:28 GMT"
java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 15:01:02 GMT"
java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 23:48:33 GMT"
java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 17:24:20 GMT"
java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 11:13:10 GMT"

是否可以解决此问题,还是应该使用som

Is there a way to solve this, or should I use something else instead of DateTime.

推荐答案

该构造函数不是某种通用的日期时间字符串解释引擎。它期望将常规ISO日期的变体定义为 YYYY-MM-DDTHH:MM:SS.SSSZ

That constructor is not some kind of universal date-time string interpreting engine. It expects variants of a regular ISO date defined as YYYY-MM-DDTHH:MM:SS.SSSZ.

您将需要定义一个格式字符串,该字符串描述您可以从中进行解析的格式。就像 EEE,dd MMM YYYY HH:mm:ss zzz
此处的Javadoc!

You will need to define a format string that describes your format that can then be parsed from. It would be something like EEE, dd MMM YYYY HH:mm:ss zzz javadoc here!

这篇关于至今字符串(无效格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆