Java String to Date stringToDate(String dateString, String dataFormat)

Here you can find the source of stringToDate(String dateString, String dataFormat)

Description

string To Date

License

Open Source License

Declaration

public static Date stringToDate(String dateString, String dataFormat) 

Method Source Code

//package com.java2s;

import java.util.Date;

public class Main {
    public static Date stringToDate(String dateString, String dataFormat) {
        if (isEmpty(dateString)) {
            return null;
        }//from   ww w.ja v  a 2s .  c om

        if (dateString.length() != 14) {
            return null;
        }

        java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(dataFormat);

        try {
            return dateFormat.parse(dateString);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return null;
    }

    public static boolean isEmpty(String input) {
        return (input == null || input.length() == 0);
    }
}

Related

  1. stringToDate(String dateString)
  2. stringToDate(String dateString)
  3. stringToDate(String dateString)
  4. stringToDate(String dateString)
  5. stringToDate(String dateString)
  6. stringToDate(String dateString, String dateFormat)
  7. stringTodate(String dateString, String format)
  8. stringToDate(String dateString, String formatStr)
  9. stringToDate(String dateString, String pattern)