Here you can find the source of formatDateTime24()
public static void formatDateTime24()
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void formatDateTime24() { // format 12 hours time to 24 hours time SimpleDateFormat displayFormat = new SimpleDateFormat("HH:mm"); SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a"); Date date = null;//w w w . j a v a 2 s .c o m try { date = parseFormat.parse("10:30 PM"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(parseFormat.format(date) + " = " + displayFormat.format(date)); } }