Java String to Date stringToDateByconf(String str, String formate)

Here you can find the source of stringToDateByconf(String str, String formate)

Description

string To Date Byconf

License

Apache License

Declaration

public static Date stringToDateByconf(String str, String formate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static Date stringToDateByconf(String str, String formate) {
        DateFormat formater;//from www  .  ja va  2s  .  c om
        formater = new SimpleDateFormat(formate);
        try {
            return (Date) formater.parse(str);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            formater = new SimpleDateFormat("yyyy-MM-dd");
            try {
                return (Date) formater.parse(str.substring(0, 10));
            } catch (ParseException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
        return new Date();
    }
}

Related

  1. stringToDate(String time, String format)
  2. stringToDate(String vStr, String vPatten)
  3. StringToDate1(String strDate)
  4. stringToDate10(String date)
  5. stringToDateAndTime(final String dateAndTimeString)
  6. StringToDateByFormat(String dateStr, String formatStr)
  7. StringToDateByformat1(String time)
  8. stringToDateForIng(String date_str)
  9. StringToDateFormat(String str, String format)