Java Parse Date Pattern YYYY parse(String dateString)

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

Description

parse

License

Open Source License

Declaration

public static Date parse(String dateString) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static final ThreadLocal<DateFormat> COMMON_FORMAT = new ThreadLocal<DateFormat>() {
        @Override/*  w w w  . ja  v a  2  s .  c  o m*/
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
    };
    private static final ThreadLocal<DateFormat> DATE_FORMAT = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd");
        }
    };

    public static Date parse(String dateString) throws ParseException {
        try {
            return COMMON_FORMAT.get().parse(dateString);
        } catch (ParseException e) {
            return DATE_FORMAT.get().parse(dateString);
        }
    }
}

Related

  1. parse(String dateStr)
  2. parse(String dateString)
  3. parse(String dateString)
  4. parse(String dateString)
  5. parse(String dateString)
  6. parse(String DateString)
  7. parse(String dateString)
  8. parse(String dateString)
  9. parse(String datestring)