我有以下字符串“29/05/2012 12:11 PM”我想将此值添加到 DateField
我是这样做的:
String dateTime = "29/05/2012 12:11 PM";
long initialDateTime = System.currentTimeMillis();
SimpleDateFormat SDF_DateTime = new SimpleDateFormat("dd/MM/yyyy hh:mm aa");
DateField DF_DateTime = new DateField("Time: ", initialDateTime , SDF_DateTime, Field.FIELD_LEFT | DrawStyle.LEFT | Field.FOCUSABLE);
DF_DateTime.setTimeZone(TimeZone.getDefault());
DF_DateTime.setDate(stringToDate(dateTime));
add(DF_DateTime);
在哪里
public Date stringToDate(String s)
{
Calendar c = Calendar.getInstance(TimeZone.getDefault());
c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(0, 2)));
c.set(Calendar.MONTH, Integer.parseInt(s.substring(3, 5)) - 1);
c.set(Calendar.YEAR, Integer.parseInt(s.substring(6, 10)));
c.set(Calendar.HOUR, Integer.parseInt(s.substring(11, 13)));
c.set(Calendar.MINUTE, Integer.parseInt(s.substring(14, 16)));
c.set(Calendar.SECOND, 0);
c.set(Calendar.AM_PM, s.substring(17, 19).toLowerCase().equals("am") ? Calendar.AM : Calendar.PM);
return c.getTime();
}
但是该字段显示:“ 30 /05/2012 12:11 AM ”
而不是“ 29 /05/2012 12:11 PM ”
如果知道有用的话,我的设备设置为以下时区的选项:“都柏林,伦敦(格林威治标准时间)”
对正在发生的事情有任何合乎逻辑的解释吗?