Here you can find the source of parseDateTime(String dateTimeString)
public static Date parseDateTime(String dateTimeString)
//package com.java2s; /**/*from w w w. j a v a2s. co m*/ * <p> * </p> * <p> * <span class="BSDLicense"> This software is distributed under the <a * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>. </span> * </p> * * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu) */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date parseDateTime(String dateTimeString) { Date d = null; try { // assume it's the US time format... d = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a").parse(dateTimeString); } catch (ParseException e) { // assume it's a universal time format (anywhere but US) try { d = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(dateTimeString); } catch (ParseException parseException) { parseException.printStackTrace(); } } return (d == null) ? new Date() : d; } }