Java String to Date stringToDate(String vStr, String vPatten)

Here you can find the source of stringToDate(String vStr, String vPatten)

Description

string To Date

License

Open Source License

Declaration

public static Date stringToDate(String vStr, String vPatten) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {

    public static Date stringToDate(String vStr, String vPatten, Locale vLocale) {
        if (vStr == null || vPatten == null || vLocale == null) {
            throw new IllegalArgumentException("The vStr and the vPatten and the vLocale must not be null");
        }/*from w w  w.  j a v  a2 s . c o  m*/

        if (vStr.equals(""))
            return null;
        try {
            SimpleDateFormat df = new SimpleDateFormat(vPatten, vLocale);
            return df.parse(vStr);
        } catch (Exception ex) {
            return null;
        }
    }

    public static Date stringToDate(String vStr, String vPatten) {
        if (vStr == null || vPatten == null) {
            throw new IllegalArgumentException("The vStr and the vPatten must not be null");
        }

        if (vStr.equals(""))
            return null;
        try {
            SimpleDateFormat df = new SimpleDateFormat(vPatten);
            return df.parse(vStr);
        } catch (Exception ex) {
            return null;
        }
    }
}

Related

  1. stringToDate(String string)
  2. stringToDate(String string, String format)
  3. stringToDate(String text)
  4. StringToDate(String thisdate, Locale locale)
  5. stringToDate(String time, String format)
  6. StringToDate1(String strDate)
  7. stringToDate10(String date)
  8. stringToDateAndTime(final String dateAndTimeString)
  9. stringToDateByconf(String str, String formate)