Java Parse Date Pattern YYYY parse(Date strDate, String pattern)

Here you can find the source of parse(Date strDate, String pattern)

Description

parse

License

Open Source License

Declaration

public static Date parse(Date strDate, String pattern) 

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 Date parse(String strDate) throws ParseException {
        return parse(strDate, getDatePattern());
    }//  ww w.  j ava  2  s. c o m

    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. parse(Class clazz, Object object)
  2. parse(Date d)
  3. parse(final String dateString)
  4. parse(final String inputDate)
  5. parse(final String s)
  6. parse(final String source)