Java examples for Date Time:Legacy Date Format
Parsing the Time Using a Custom Format
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] argv) { try {// w w w. java 2s . co m DateFormat formatter = new SimpleDateFormat("hh.mm.ss a"); Date date = (Date) formatter.parse("02.36.33 PM"); System.out.println(date); formatter = new SimpleDateFormat("HH:mm:ss Z"); date = (Date) formatter.parse("22:14:02 -0500"); System.out.println(date); } catch (ParseException e) { } } }