Java Parse Date parseDateTime(String dateTimeString)

Here you can find the source of parseDateTime(String dateTimeString)

Description

parse Date Time

License

BSD License

Declaration

public static Date parseDateTime(String dateTimeString) 

Method Source Code

//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;
    }
}

Related

  1. parseDateTime(String date, String format, String locale, String timeZone)
  2. parseDateTime(String date, String time)
  3. parseDateTime(String dateTime)
  4. parseDateTime(String dateTimeStr)
  5. parseDateTime(String dateTimeString)
  6. parseDateTime(String dateTimeString, String[] validFormats, String outputFormat)
  7. parseDateTime(String format, String dateStr)
  8. parseDateTime(String fullDateParam, String unixDateParam, Map request)
  9. parseDateTime(String s)