Java String to Date stringToDate(String dateStr)

Here you can find the source of stringToDate(String dateStr)

Description

Converts a String with format DateUtils.DATE_FORMAT to a Date.

License

Educational Community License

Declaration

public static Date stringToDate(String dateStr) 

Method Source Code

//package com.java2s;
//License from project: Educational Community License 

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

public class Main {
    private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
            "yyyy-MM-dd");

    /**/* w  ww  .  ja v a 2  s .  com*/
     * Converts a String with format DateUtils.DATE_FORMAT to a Date.
     * Returns null if the parse fails.
     */
    public static Date stringToDate(String dateStr) {
        if (dateStr == null)
            return null;

        try {
            return DATE_FORMAT.parse(dateStr);
        } catch (ParseException ex) {
            return null;
        }
    }
}

Related

  1. stringToDate(String date, String format)
  2. stringToDate(String date, String pattren)
  3. stringToDate(String datecontent, String format)
  4. stringToDate(String dateStr)
  5. StringToDate(String dateStr)
  6. stringToDate(String dateStr, SimpleDateFormat dateFormat)
  7. StringtoDate(String dateStr, String format)
  8. stringToDate(String dateString)
  9. stringToDate(String dateString)