Java Date Parse dateParser(String param)

Here you can find the source of dateParser(String param)

Description

date Parser

License

Open Source License

Declaration

public static Date dateParser(String param) 

Method Source Code


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

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

public class Main {
    private static String defaultDatePattern = "yyyy-MM-dd";
    public static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");

    public static Date dateParser(String param) {
        Date date = null;/*from  w  w  w . ja  v  a 2s .co m*/
        try {
            date = dateFormatter.parse(param);
        } catch (ParseException ex) {
        }
        return date;
    }

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

    public static Date parse(String strDate, String pattern) {
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        try {
            return df.parse(strDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    public static Date parse(Date strDate, String pattern) {
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        try {
            return df.parse(df.format(strDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String getDatePattern() {
        return defaultDatePattern;
    }

    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);
    }
}

Related

  1. dateParse(String date2BeParsed)
  2. dateParseFromMyJsFormat(String jsDate)
  3. dateParser()
  4. dateParser(Date date)
  5. dateParser(String dateStr, String inputDateFormat, String outputDateFormat)
  6. dateParseShortString(Date date)
  7. dateStringToDate(String dateString, String DateStringType)
  8. dateStringToDateObject(String dateString, String dateFormat)
  9. datetime(String s)