0

我无法获取要由 DateTimeFormat 格式解析的字符串。这是输入字符串: Thu Apr 07 00:00:00 EDT 2011

和我的格式:
DateTimeFormat.getFormat("EEE MMM dd HH:mm:ss vvv yyyy");

我读过这是正确的格式字符串,但对我来说它没有正确解析。这是代码:

public class YcDateColumn extends TextColumn<JSONObject> {

    DateTimeFormat fmtC = DateTimeFormat.getFormat("dd-MMM-yyyy");
    DateTimeFormat fmtB = DateTimeFormat.getFormat("MMM dd, yyyy hh:mm:ss a");
    DateTimeFormat fmtA = DateTimeFormat.getFormat("EEE MMM dd HH:mm:ss vvv yyyy");


    private String key = null;
    private String def = null;

    public YcDateColumn(String aKey, String aDefault) {
        super();
        key = aKey;
        def = aDefault;
    }

    public YcDateColumn(String aKey) {
        this(aKey, null);
    }

    @Override
    public String getValue(JSONObject aObj) {
            System.out.println("YcDateColumn - object= " + aObj);
        JSONValue mVal = aObj.get(key);
        if (mVal == null)
            return def;
        System.out.println("YcDateColumn -  about to parse string: " + mVal.isString().stringValue());
        return fmtC.format(fmtA.parse(mVal.isString().stringValue()));
    }

}

最后一个 System.out 打印此文本(要解析的字符串):YcDateColumn - about to parse string: Thu Apr 07 00:00:00 EDT 2011

我错过了什么!?谢谢您的帮助!

-埃里克

4

1 回答 1

0

格式字符串中的 zzz 需要一个数字(偏移量)。你的日期有美国东部时间。您需要使用 v 作为时区。

于 2011-04-12T03:32:01.493 回答