Java String to Date toDate(String dateString)

Here you can find the source of toDate(String dateString)

Description

to Date

License

Apache License

Declaration

public static Date toDate(String dateString) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.google.common.base.Strings;

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

    public static Date toDate(String dateString) {
        if (Strings.isNullOrEmpty(dateString)) {
            return null;
        }// w  w  w  .j a  v a  2s  . c  o  m
        try {
            return DATE_FORMAT.parse(dateString);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. toDate(String date, String format)
  2. toDate(String dateStr)
  3. toDate(String dateStr)
  4. toDate(String dateStr, String format)
  5. toDate(String dateStr, String pattern)
  6. toDate(String dateString)
  7. toDate(String dateString)
  8. toDate(String dateString, Locale locale)
  9. toDate(String dateString, String dateFormatPattern)