Here you can find the source of getDayMonthYear(Date aDate, boolean isAddSpace)
get day month year
Parameter | Description |
---|---|
aDate | a parameter |
public static final String[] getDayMonthYear(Date aDate, boolean isAddSpace)
//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; } }