Java Parse Date Pattern YYYY parseString(String strDate)

Here you can find the source of parseString(String strDate)

Description

parse String

License

Open Source License

Declaration

public static String parseString(String strDate) throws ParseException 

Method Source Code


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

public class Main {
    public static String defaultDatePattern = "yyyy-MM-dd";
    public static String defaultDatePattern1 = "yyyy-MM-dd HH:mm:ss";

    public static String parseString(String strDate) throws ParseException {
        if (strDate == null || "".equals(strDate)) {
            return null;
        }//from   ww w .  ja  v  a2  s  .c o  m
        if (strDate.length() > 19) {
            strDate = strDate.substring(0, 19);
        }
        Date bufferDate = parse(strDate, defaultDatePattern1);
        return format(bufferDate);
    }

    public static Date parse(String strDate) throws ParseException {
        return parse(strDate, getDatePattern());
    }

    public static Date parse(String strDate, String pattern) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        return df.parse(strDate);
    }

    public static String format(Date date) {
        return format(date, getDatePattern());
    }

    public static String format(Date date, String pattern) {
        String returnValue = "";

        if (date != null) {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            returnValue = df.format(date);
        }

        return (returnValue);
    }

    public static String getDatePattern() {
        return defaultDatePattern;
    }
}

Related

  1. parseSipDateTime(String dateStr)
  2. parseSolrDate(String date)
  3. parseSpaydDate(String date, TimeZone tz)
  4. parseString(String date)
  5. parseString(String dateStr)
  6. parseString2Calendar(String date)
  7. parseString2Date(String date)
  8. parseString2Date(String sDate, String format)
  9. parseString2Long(String strDate)