首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Camel Bindy日期格式解组问题

Camel Bindy日期格式解组问题
EN

Stack Overflow用户
提问于 2015-02-20 00:34:51
回答 1查看 2.2K关注 0票数 1

对于从CSV文件解析日期字段的Apache数据格式,我遇到了一个问题。

在CSV中的日期是02/11/2015 03:34:49 PM

在Bindy类中注释为

代码语言:javascript
复制
@DataField(pos = 8,pattern="MM/dd/yyyy hh:mm:ss a")
private Date time;

异常以下

提供的日期不符合所定义的模式,位置: 8,行:1在org.apache.camel.dataformat.bindy.BindyCsvFactory.bind(BindyCsvFactory.java:213) at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:185) at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:67)

如果CSV中的日期是以2/11/2015 03:34:49 PM,的形式给出,而月份字段中没有0的话,它就能工作。

我用的是骆驼2.14.1。

我在这里做错什么了吗?

EN

回答 1

Stack Overflow用户

发布于 2015-02-22 21:44:44

来自DatePatternFormat.java的源代码:

代码语言:javascript
复制
public Date parse(String string) throws Exception {

    Date date;
    DateFormat df = this.getDateFormat();

    ObjectHelper.notNull(this.pattern, "pattern");

    // Check length of the string with date pattern
    // To avoid to parse a string date : 20090901-10:32:30 when
    // the pattern is yyyyMMdd

    if (string.length() <= this.pattern.length()) {

        // Force the parser to be strict in the syntax of the date to be
        // converted
        df.setLenient(false);
        date = df.parse(string);

        return date;

    } else {
        throw new FormatException("Date provided does not fit the pattern defined");
    }
}

它检查已解析的字符串是否小于模式。

然后将您的模式更改为MM/dd/yyyy hh:mm:ss aa可以解决您的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28619736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档