【发布时间】:2016-11-23 02:02:40
【问题描述】:
我以这种格式将时间存储在数据库中:"hh:mm:ss"(例如 09:30:00)然后检索并尝试以这种格式向用户显示它:“hh:mm AM/PM”(例如- 上午 09:30)。
我正在使用以下代码进行转换:
DateFormat currentTime = new SimpleDateFormat("hh:mm a");
String startTimeInSF = currentTime.format(startTime);
String endTimeInSF = currentTime.format(endTime);
其中startTime 和endTime 是hh:mm:ss 格式,但上面的代码会产生这个错误:java.lang.IllegalArgumentException: Bad class: class java.lang.String。
请告诉我如何才能成功地将时间从hh:mm:ss 转换为hh:mm AM/PM?
【问题讨论】:
-
试试这个“hh:mm tt”
-
@PrasannaKumarJ 失败!产生了这个错误:
java.lang.IllegalArgumentException: Unknown pattern character 't' -
您需要一个
SimpleDateFormat将您的日期从原始格式解析,另一个SimpleDateFormat将结果格式化为新格式。 -
发帖前搜索 Stack Overflow。
标签: java android time date-format simpledateformat