java.text.ParseException:Unparseable date:" 01:19 PM" [英] java.text.ParseException: Unparseable date: "01:19 PM"

查看:115
本文介绍了java.text.ParseException:Unparseable date:" 01:19 PM"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just try to parse a simple time! Here is my code:

   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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆