Java Parse Date Pattern YYYY parseSimpleDate(String string, Date defaultDate)

Here you can find the source of parseSimpleDate(String string, Date defaultDate)

Description

parse Simple Date

License

Apache License

Declaration

public static Date parseSimpleDate(String string, Date defaultDate) 

Method Source Code


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

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

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

    public static Date parseSimpleDate(String string, Date defaultDate) {
        if (string == null) {
            return defaultDate;
        }//  w  w w .j a va2s  . c  om

        try {
            return SIMPLE_DAY_FORMAT.parse(string);
        } catch (ParseException e) {
            return defaultDate;
        }
    }

    public static Date parse(String pattern, String dateStr) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        return sdf.parse(dateStr);
    }
}

Related

  1. parseSalesDate(final String ymd)
  2. parseSecureDate(final String dateString)
  3. parseSegKeyDate4Display(String source)
  4. parseSessionTime(String response)
  5. parseSilently(String p_string)
  6. parseSipDateTime(String dateStr)
  7. parseSolrDate(String date)
  8. parseSpaydDate(String date, TimeZone tz)
  9. parseString(String date)