gpt4 book ai didi

java.text.ParseException : Unparseable date: "01:19 PM" 异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:50:41 25 4
gpt4 key购买 nike

我只是尝试解析一个简单的时间!这是我的代码:

   String s = "01:19 PM";
Date time = null;
DateFormat parseFormat = new SimpleDateFormat("hh:mm aa");
try {
time = parseFormat.parse(s);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

我遇到了这个异常:

java.text.ParseException: Unparseable date: "01:19 PM"
at java.text.DateFormat.parse(Unknown Source)

最佳答案

这个有效:

  public static void main(String[] args) throws Exception {
String s = "01:19 PM";
Date time = null;
DateFormat parseFormat = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
System.out.println(time = parseFormat.parse(s));
}

输出:

  Thu Jan 01 13:19:00 KST 1970

关于java.text.ParseException : Unparseable date: "01:19 PM" 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25524284/

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