Java Parse Date Pattern YYYY parse(String time)

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

Description

parse

License

Apache License

Declaration

public static Date parse(String time) 

Method Source Code


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

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

public class Main {
    public static final SimpleDateFormat day = new SimpleDateFormat("yyyy-MM-dd");
    public static final SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static final SimpleDateFormat microSeconds = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    public static Date parse(String time) {
        if (time == null || time.isEmpty())
            return null;
        try {//from   w  ww  .  j  ava  2  s . co m
            return dayTime.parse(time);
        } catch (Exception ex) {
        }
        try {
            return day.parse(time);
        } catch (Exception e) {
        }
        if (time.matches("\\d{10,17}")) {
            if (time.length() == 17) {
                try {
                    return microSeconds.parse(time);
                } catch (Exception e) {
                }
            } else if (time.length() == 13) {
                return new Date(Long.valueOf(time));
            } else if (time.length() == 10) {
                return new Date(Long.valueOf(time) * 1000);
            }
        }
        return null;
    }
}

Related

  1. parse(String string)
  2. parse(String string)
  3. parse(String stringData)
  4. parse(String text)
  5. parse(String text)
  6. parse(String time, String df)
  7. parse1(String DateString, String dateTimeSeparator)
  8. parse2DateString(String date)
  9. parse_default(String time)