gpt4 book ai didi

java - 无法在java中将字符串日期解析为时间戳

转载 作者:行者123 更新时间:2023-12-01 18:02:01 25 4
gpt4 key购买 nike

我的日期格式示例 = "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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com