我想將RC3339時間格式轉換爲MM-dd-yyyy hh:mm a,但它在sampleDate處顯示空值。Regd無法解析日期:
timestamp = rcobj.getString("timestamp");
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss+SSSZ", Locale.US);
Date sampleDate = sdf.parse(timestamp, new ParsePosition(0));
sdf = new SimpleDateFormat("MM-dd-yyyy hh:mm a", Locale.US);
if (timestamp != null) {
timestamp = sdf.format(sampleDate);
}
'timestamp'的價值是什麼?爲什麼你解析它,如果它可能是空的,而不先檢查? (另外,我假設這是Java,但是如果你這樣標記它,它會有所幫助......) – 2012-03-10 20:30:38