Java Parse Date parseDateWithoutTime(final String date)

Here you can find the source of parseDateWithoutTime(final String date)

Description

parse Date Without Time

License

Apache License

Declaration

public static Date parseDateWithoutTime(final String date) 

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;

import com.google.common.base.Strings;

public class Main {
    public static final DateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy");

    public static Date parseDateWithoutTime(final String date) {

        return parseDateWithoutTime(date, false);
    }//from  w  ww . j  a  v  a 2  s . c o m

    public static Date parseDateWithoutTime(final String date, final boolean permissive) {

        final Date res = null;

        if (!permissive || !Strings.isNullOrEmpty(date)) {

            try {

                return DEFAULT_DATE_FORMAT.parse(date);
            } catch (final ParseException e) {

                if (!permissive) {

                    throw new RuntimeException("Error when parsing date : " + date, e);
                }
            }
        }

        return res;
    }
}

Related

  1. parseDateToString(Date datetime)
  2. parseDateToString(final Date date, final String dateFormat, final String lang)
  3. parseDateValue(String value)
  4. parseDateWithFormat(String date, SimpleDateFormat dateFormat, Date defaultDate)
  5. parseDateWithLeniency(final String str, final Locale locale, final String[] parsePatterns, final boolean lenient)
  6. parseDateWithPattern(Date value, String pattern)
  7. parseDateWithPattern(String dateValue, String pattern)
  8. parseDateWithTimezone(String dateValue)