Java String to Date strToDate(String i_StrDate, String i_Format)

Here you can find the source of strToDate(String i_StrDate, String i_Format)

Description

str To Date

License

Open Source License

Declaration

public static java.util.Date strToDate(String i_StrDate, String i_Format) throws ParseException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.*;

public class Main {
    public static final SimpleDateFormat SDF_FULL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static java.util.Date strToDate(String i_Today, String i_Hour, String i_Minute) {
        try {//from  w  ww .  java  2  s .  com
            if (i_Today == null || i_Hour == null || i_Minute == null) {
                return null;
            }

            return SDF_FULL.parse(i_Today.trim() + " " + i_Hour.trim() + ":" + i_Minute.trim() + ":00");
        } catch (Exception e) {
            // e.printStackTrace();
        }

        return null;
    }

    public static java.util.Date strToDate(String i_StrDate) {
        try {
            if (i_StrDate == null || "".equals(i_StrDate.trim())) {
                return null;
            }

            return SDF_FULL.parse(i_StrDate);
        } catch (Exception e) {
            // e.printStackTrace();
        }

        return null;
    }

    public static java.util.Date strToDate(String i_StrDate, String i_Format) throws ParseException {
        SimpleDateFormat SDF_My = new SimpleDateFormat(i_Format);

        try {
            return SDF_My.parse(i_StrDate);
        } catch (ParseException e) {
            throw e;
        }
    }

    public static java.util.Date strToDate(String i_StrDate, SimpleDateFormat i_SDF) throws ParseException {
        try {
            return i_SDF.parse(i_StrDate);
        } catch (ParseException e) {
            throw e;
        }
    }
}

Related

  1. StrToDate(String dateFormat)
  2. strToDate(String dateInString)
  3. strToDate(String dateStr, String dateFormat)
  4. strToDate(String dateStr, String format)
  5. strToDate(String format, String dateStr)
  6. strToDate(String input, String format)
  7. strToDate(String s, Date defaultValue)
  8. strToDate(String str)
  9. strToDate(String str, String format, java.util.Date defaultValue)