java.text.ParseException:无法解析的日期:“Thu Jan 19 2012 08:00 PM”

我想解析一个约会.我的字符串日期是“Thu Jan 19 2012 08:00 PM”.我要解析的代码是:
format = new SimpleDateFormat("EEE MMM dd yyyy hh:mm aaa");
this.settDate(new Timestamp((format.parse(sDate)).getTime()));

但是,它不起作用.我怎么解析这个日期?

完整的方法是:

public void saveTask(int iDevice,String description,String sDate) throws ParseException {
    format = new SimpleDateFormat("EEE MMM dd yyyy hh:mm aaa");
    this.setideviceid(iDevice);
    this.setsDescription(description);
    this.settDate(new Timestamp((format.parse(sDate)).getTime()));
    DatabaseManager.save(this);
}

例外:

java.text.ParseException: Unparseable date: "Thu Jan 19 2012 01:00 AM"

调试图片

谢谢!

解决方法

尝试以下代码…经过测试和工作
String dateStr = "Thu Jan 19 2012 01:00 PM";
    DateFormat readFormat = new SimpleDateFormat( "EEE MMM dd yyyy hh:mm aaa");

    DateFormat writeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = null;
    try {
       date = readFormat.parse( dateStr );
    } catch ( ParseException e ) {
        e.printstacktrace();
    }

    String formattedDate = "";
    if( date != null ) {
    formattedDate = writeFormat.format( date );
    }

    System.out.println(formattedDate);

输出为2012-01-19 13:00:00

干杯!!!乐于帮助!!!

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...