Can't parse Date with DateTimeFormat
I can't get a string to be parsed by a DateTimeFormat format. Here is the input string :
Thu Apr 07 00:00:00 EDT 2011
and my format:
DateTimeFormat.getFormat("EEE MMM dd HH:mm:ss vvv yyyy");
I've read that this is the correct format string, but for me it's not parsing correctly. Here is the code:
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()));
}
}
The last System.out prints this text (the string to parse): YcDateColumn - about to pa开发者_如何学运维rse string: Thu Apr 07 00:00:00 EDT 2011
What am I missing!? Thanks for the help!
-Eric
zzz in your format string requires a number (the offset). Your date has EDT. You will need to use v for the timezone.
精彩评论