Converting XX:XX AM/PM to 24 Hour Clock

前端 未结 6 1729
抹茶落季
抹茶落季 2021-02-15 16:41

I have searched google and I cannot find out how you can take a string: xx:xx AM/PM (ex. 3:30 PM) and change it so that it is now in 24 hours.

So for e

6条回答
  •  臣服心动
    2021-02-15 17:04

    Try

      String time = "3:30 PM";
    
        SimpleDateFormat date12Format = new SimpleDateFormat("hh:mm a");
    
        SimpleDateFormat date24Format = new SimpleDateFormat("HH:mm");
    
        System.out.println(date24Format.format(date12Format.parse(time)));
    

    output:

    15:30
    

提交回复
热议问题