我正在尝试将“7:05 AM”转换为时间戳,但它无效。
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
Date parsedDate = dateFormat.parse("7:05AM");
Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());
}
catch(Exception e)
{
}
答案 0 :(得分:0)
将SimpleDateFormat(“yyyy-MM-dd hh:mm a”)更改为(“hh:mm a”)其工作正常
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a");
Date parsedDate = dateFormat.parse("7:05 AM");
Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());
System.out.println(timestamp.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}