我想将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