Java Day getDay(java.util.Date date)

Here you can find the source of getDay(java.util.Date date)

Description

get Day

License

Apache License

Declaration

public static java.util.Date getDay(java.util.Date date) 

Method Source Code

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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static java.util.Date getDay(java.util.Date date) {
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.setTime(date);//  w  ww  .j  a  va2 s .c  om
        String s = new java.text.SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sf.parse(s);
        } catch (ParseException e) {
            return null;
        }
    }

    public static java.util.Date getDay(String date) {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sf.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }

    public static String format(Date date, String pattern) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat sf = new SimpleDateFormat(pattern);
        return sf.format(date);
    }

    public static String format(Date date) {
        return format(date, "yyyy-MM-dd");
    }

    public static Date parse(String dateStr) {
        return parse(dateStr, "yyyy-MM-dd");
    }

    public static Date parse(String dateStr, String formate) {
        SimpleDateFormat sf = new SimpleDateFormat(formate);
        try {
            return sf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getDay(Date date)
  2. getDay(Date date)
  3. getDay(Date date)
  4. getDay(Date date)
  5. getDay(Date date, HashMap date2day)
  6. getDay(SimpleDateFormat df, String dateStr)
  7. getDay(String aDate)
  8. GetDay(String agmipDate)
  9. getDAY(String strDate)