无法理解日期解析

时间:2013-01-28 12:52:56

标签: java date

我有字符串"1/28/2013 3:26:51 PM"

SimpleDateFormat formatter = new SimpleDateFormat("M/dd/yyyy h:mm:ss a");
    try {
        this.createDate = formatter.parse(xmlPhoto.getCreateDate());
        this.shootDate = formatter.parse(xmlPhoto.getShootDate());
    } catch (ParseException e) {
        e.printStackTrace();
    }

我想从这个String中创建一个Date对象,但我得到一个ParseExceprion和offset = 19.

1 个答案:

答案 0 :(得分:5)

AM/PM标记可能与默认Locale中的标记不匹配。试试:

new SimpleDateFormat("M/dd/yyyy h:mm:ss a", Locale.ENGLISH)