0
我想通过从JSON获取日期,将它放入类的属性中,并从中获取它以便将其显示在字符串中。放入类属性时出现错误的日期格式
我的课的重要一方是:
Date _begin;
public Date getBegin(){ return this._begin; }
public void setBegin(Date begin){ this._begin = begin; }
和我有Testoutput这里(JSON的环路的重要组成部分)使用它:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
String tempDateString = c.getString("begin");
try {
Date date = null;
try {
date = dateFormat.parse(tempDateString);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
thisData.setBegin(date);
Log.d("SimpleDateFormat(EventActivity Template)", "dd-MM-yyyy HH:mm:ss");
Log.d("SimpleDateFormat(EventActivity String)", tempDateString);
Log.d("SimpleDateFormat(EventActivity Output)", dateFormat.format(thisData.getBegin()));
} catch (ParseException e) {
e.printStackTrace();
}
而且testoutput是:
05-28 10:02:31.588: D/SimpleDateFormat(EventActivity Template)(10396): dd-MM-yyyy HH:mm:ss
05-28 10:02:31.588: D/SimpleDateFormat(EventActivity String)(10396): 2013-09-07 20:00:00
05-28 10:02:31.588: D/SimpleDateFormat(EventActivity Output)(10396): 05-03-0013 20:00:00
为什么我回到日期这种奇怪的格式?
tempDateString显然不符合你的格式。这是行不通的。 – njzk2
为解析你使用错误的模式。它应该是“yyyy-MM-dd HH:mm:ss” – Blackbelt
omg。你的权利。那很明显。对不起,也许我需要一杯咖啡。 –