在java android中显示Unparseable日期:“09:30 AM”(在偏移6处)

时间:2017-12-29 05:30:51

标签: java android

当我将参数传递为“09:30 AM”时,它会在android中返回异常 显示无法解释的日期:“09:30 AM”(在偏移6处)

 public static String convertTo24Hour (String now){
        String time24="";
          try {
            SimpleDateFormat inFormat = new SimpleDateFormat("hh:mm a");
            SimpleDateFormat outFormat = new SimpleDateFormat("HH:mm");
            time24 = outFormat.format(inFormat.parse(now));
        } catch (Exception e) {
            System.out.println("Exception : " + e.getMessage());
        }
        return time24;
    }

1 个答案:

答案 0 :(得分:-1)

试试这个

public static String convertTo24Hour (String now){
    String time24="";
    try {
        SimpleDateFormat inFormat = new SimpleDateFormat("hh:mm a",Locale.getDefault());
        SimpleDateFormat outFormat = new SimpleDateFormat("H:mm", Locale.getDefault());
        time24 = outFormat.format(inFormat.parse(now));
    } catch (Exception e) {
        System.out.println("Exception : " + e.getMessage());
    }
    return time24;
}

根据您的需要更改区域设置。 希望这会有所帮助..