java.text.ParseException:无法解析的日期:“Thu Jan 19 2012 08:00 PM”
发布时间:2020-05-24 22:30:58 所属栏目:Java 来源:互联网
导读:我想解析一个约会.我的字符串日期是“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())); 但是,它不起作用.我怎么解析这个日期? 完
|
我想解析一个约会.我的字符串日期是“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 干杯!!!乐于帮助!!! (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
