我无法通过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
我错过了什么!?谢谢你的帮助!
-Eric
答案 0 :(得分:0)
格式字符串中的zzz需要一个数字(偏移量)。你的约会对象有EDT。您需要使用v作为时区。