我的日期格式示例 = "jan 14, 2015"现在我将此字符串日期转换为时间戳,但此代码会引发 ParseException。
format = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss", Locale.ENGLISH);
try {
format.setTimeZone(TimeZone.getTimeZone("Asia/Bangladesh"));
Date date = format.parse(str_date);
Timestamp timeStampDate = new java.sql.Timestamp(date.getTime());
return timeStampDate;
} catch (ParseException e) {
e.getCause().printStackTrace();
return null;
}
那么我该如何解决这个异常呢???提前致谢。
最佳答案
将您的模式更改为:format = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
因为您没有时间部分
关于java - 无法在java中将字符串日期解析为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40212736/