Java Date to Day getDayMonthYear(Date aDate, boolean isAddSpace)

Here you can find the source of getDayMonthYear(Date aDate, boolean isAddSpace)

Description

get day month year

License

Open Source License

Parameter

Parameter Description
aDate a parameter

Declaration

public static final String[] getDayMonthYear(Date aDate, boolean isAddSpace) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//from w ww. ja va 2 s . c om
     * <p>get day month year</p>
     * 
     * @param aDate
     * @return
     */
    public static final String[] getDayMonthYear(Date aDate, boolean isAddSpace) {
        String[] dmys = new String[3];
        if (aDate != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(aDate);
            int day = cal.get(Calendar.DAY_OF_MONTH);
            if (day < 10) {
                if (isAddSpace) {
                    dmys[0] = "0 " + day;
                } else {
                    dmys[0] = "0" + day;
                }
            } else {
                String tmp = day + "";
                if (isAddSpace) {
                    dmys[0] = tmp.substring(0, 1) + " " + tmp.substring(1, 2);
                } else {
                    dmys[0] = tmp;
                }
            }
            int month = cal.get(Calendar.MONTH) + 1;
            if (month < 10) {
                if (isAddSpace) {
                    dmys[1] = "0 " + month;
                } else {
                    dmys[1] = "0" + month;
                }
            } else {
                String tmp = month + "";
                if (isAddSpace) {
                    dmys[1] = tmp.substring(0, 1) + " " + tmp.substring(1, 2);
                } else {
                    dmys[1] = tmp;
                }
            }
            String year = cal.get(Calendar.YEAR) + "";
            if (isAddSpace) {
                dmys[2] = year.substring(0, 1) + " " + year.substring(1, 2) + " " + year.substring(2, 3) + " "
                        + year.substring(3, 4);
            } else {
                dmys[2] = year;
            }
        }
        return dmys;
    }
}

Related

  1. getDayEnd(Date date)
  2. getDayEnd(Date date)
  3. getDayEnd(Date obj)
  4. getDayEnd(final Date date, TimeZone timezone)
  5. getDayFromDate(Date date)
  6. getDayNumber(Date startDate, Date endDate)
  7. getDayOfDate(Date date)
  8. getDayOfThisYear(Date currentdate)
  9. getDayOfYear(Date date)