gpt4 book ai didi

android - 尝试使用格式 "2018-07-30T12:31:02"格式化日期时出现无法解析的日期异常

转载 作者:行者123 更新时间:2023-11-29 23:41:57 26 4
gpt4 key购买 nike

我正在尝试使用以下代码从服务器格式化日期

 private SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa", Locale.getDefault());
try {

Date dtShiftDate = format.parse(cursor.getString(cursor.getColumnIndex("shiftdetails_ShiftStartTime")));
Date dtCurrDate = format.parse(strCurrDate);
if (dtShiftDate.getTime() != dtCurrDate.getTime()) {
bLastShiftNotEnded = true;
}
} catch (java.text.ParseException e) {
Log.e("Date parse exception",e.getMessage());
}

我遇到了无法解析的异常

最佳答案

There is something wrong either with the String you are providing to the parse() method, or with the Format you are providing. You should check again carefully both of these aspects, and of course develop a range of tests that confirm the correctness of your Format.

你的 logcat 抛出

java.text.ParseException: Unparseable date: 

尝试

new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss", Locale.getDefault());

仅供引用

h   Hour in am/pm (1-12)
H Hour in day (0-23)

关于android - 尝试使用格式 "2018-07-30T12:31:02"格式化日期时出现无法解析的日期异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51763119/

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