Java Parse Date Pattern YYYY parse(String dateStr)

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

Description

parse

License

Open Source License

Parameter

Parameter Description
dateStr a parameter

Declaration

public static Date parse(String dateStr) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final SimpleDateFormat defaultFormater = new SimpleDateFormat("yyyyMMdd");
    private static final SimpleDateFormat customizedFormater = new SimpleDateFormat("yyyyMMdd");

    public static Date parse(String dateStr, String pattern) {
        synchronized (customizedFormater) {
            if (null != pattern && !"".equals(pattern.trim())) {
                customizedFormater.applyPattern(pattern);
            } else {
                throw new IllegalArgumentException("pattern can not be empty");
            }//  ww  w .  j  a  v a  2s .c om
            try {
                return customizedFormater.parse(dateStr);
            } catch (ParseException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }

    public static Date parse(String dateStr) {
        synchronized (defaultFormater) {
            try {
                return defaultFormater.parse(dateStr);
            } catch (ParseException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }
}

Related

  1. parse(String date)
  2. parse(String date, String format)
  3. parse(String dateAsString)
  4. parse(String DateStr)
  5. parse(String datestr)
  6. parse(String dateStr)
  7. parse(String dateString)
  8. parse(String dateString)
  9. parse(String dateString)