可能重复:
如何在 java 中解析日期?
我想将字符串"11-10-10 12:00:00"
转换为Date
对象,但我不能这样做。你能帮帮我吗?
我有 Date 对象,其值为“Mon Oct 11 00:00:00 IST 2010”
DateFormat newDateFormat = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
String strDate = newDateFormat.format(tempDate);
//**i got strDate as strDate is : 11-10-10 12:00:00**
DateFormat newDateFormat1 = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
try {
tempDate = newDateFormat1.parse(strDate);
// **getting tempDate as - Mon Oct 11 00:00:00 IST 2010**
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}