Java Parse Date parseDateStringToDate(DateFormat format, String dateString)

Here you can find the source of parseDateStringToDate(DateFormat format, String dateString)

Description

parse Date String To Date

License

Open Source License

Declaration

public static Date parseDateStringToDate(DateFormat format, String dateString) 

Method Source Code

//package com.java2s;

import java.text.DateFormat;
import java.text.ParseException;

import java.util.Date;

import java.util.TimeZone;

public class Main {

    public static Date parseDateStringToDate(DateFormat format, String dateString) {
        if (format != null) {
            synchronized (format) {
                try {
                    return format.parse(dateString);
                } catch (ParseException e) {
                    return null;
                }/*from www  . j  a  va 2 s . c o m*/
            }
        } else {
            // String message = "format is null,the dataString is " +
            // dateString;
            return null;
        }

    }

    public static Date parseDateStringToDate(DateFormat format, String time, TimeZone timeZone) {
        synchronized (format) {
            try {
                format.setTimeZone(timeZone);
                return format.parse(time);
            } catch (ParseException e) {
                return null;
            }
        }
    }
}

Related

  1. parseDateString(String dateStr)
  2. parseDateString(String dateString)
  3. parseDateString(String pattern, String dateString)
  4. parseDateString(String s)
  5. parseDateString(TimeZone tz, String dateString)
  6. parseDateStrShort(String date)
  7. parseDateSubset(String value, String[] parsePatterns, Locale l, TimeZone tz)
  8. parseDateTime(@Nullable String s)
  9. parseDateTime(final String dateTime)