Here you can find the source of formatDateTime12(String dateStr)
public static void formatDateTime12(String dateStr)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static void formatDateTime12(String dateStr) { // format 12 hours time to 24 hours time SimpleDateFormat parseFormat = new SimpleDateFormat("dd/mm/yy HH:mm:ss zz"); SimpleDateFormat displayFormat = new SimpleDateFormat("dd/mm/yy hh:mm:ss a zz"); // time zone String[] tz = dateStr.split(" "); TimeZone firstTime = TimeZone.getTimeZone(tz[tz.length - 1]); parseFormat.setTimeZone(firstTime); displayFormat.setTimeZone(firstTime); Date date = null;// ww w . j a v a2 s.com try { date = parseFormat.parse(dateStr); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(parseFormat.format(date) + " = " + displayFormat.format(date)); } }