Java Parse Date Pattern YYYY parse(String str)

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

Description

parse

License

Open Source License

Declaration

public static Date parse(String str) 

Method Source Code


//package com.java2s;

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

public class Main {
    public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    private static final String INIT_DATE_TIME = "1900-01-01 00:00:00";

    public static Date parse(String str) {
        SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        try {/*w w w  .  ja va  2 s.co  m*/
            if (str.length() < INIT_DATE_TIME.length()) {
                str += INIT_DATE_TIME.substring(str.length() + 1);
            }
            return sdf.parse(str);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. parse(String source)
  2. parse(String source)
  3. parse(String source)
  4. parse(String source, Date defaultValue)
  5. parse(String str)
  6. parse(String str)
  7. parse(String str)
  8. parse(String str)
  9. parse(String strDate)