List of usage examples for java.util Calendar DAY_OF_MONTH
int DAY_OF_MONTH
To view the source code for java.util Calendar DAY_OF_MONTH.
Click Source Link
get
and set
indicating the day of the month. From source file:Main.java
public static LinkedHashMap<String, Integer> getDateMap(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);// w ww . j a v a2s . com LinkedHashMap<String, Integer> datemap = new LinkedHashMap<String, Integer>(); datemap.put("year", cal.get(Calendar.YEAR)); datemap.put("month", cal.get(Calendar.MONTH)); datemap.put("day", cal.get(Calendar.DAY_OF_MONTH)); datemap.put("hour", cal.get(Calendar.HOUR_OF_DAY)); datemap.put("minute", cal.get(Calendar.MINUTE)); datemap.put("second", cal.get(Calendar.SECOND)); datemap.put("millisecond", cal.get(Calendar.MILLISECOND)); return datemap; }
From source file:Main.java
public static String getDateTimeString(Calendar calendar) { int year = calendar.get(Calendar.YEAR); // if (year>3900) year-=1900; SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault()); //Date date = new Date(); return dateFormat .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); }
From source file:Main.java
public static String getDateTime(Calendar calendar) { int year = calendar.get(Calendar.YEAR); // if (year>3900) year-=1900; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); //Date date = new Date(); return dateFormat .format(new Date(year - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); }
From source file:Main.java
public static int compareDate(Calendar time1, Calendar time2) { int result = -1; if (time1.getTimeInMillis() == time2.getTimeInMillis()) { result = 0;// w ww. j ava2s . c o m } else if (time1.get(Calendar.YEAR) == time2.get(Calendar.YEAR)) { result = 6; if (time1.get(Calendar.MONTH) == time2.get(Calendar.MONDAY)) { result = 5; if (time1.get(Calendar.DAY_OF_MONTH) == time2.get(Calendar.DAY_OF_MONTH)) { result = 4; if (time1.get(Calendar.HOUR_OF_DAY) == time2.get(Calendar.HOUR_OF_DAY)) { result = 3; if (time1.get(Calendar.MINUTE) == time2.get(Calendar.MINUTE)) { result = 2; if (time1.get(Calendar.SECOND) == time2.get(Calendar.SECOND)) { result = 1; } } } } } } else if (time1.get(Calendar.YEAR) / 100 == time2.get(Calendar.YEAR) / 100) { result = 7; } return result; }
From source file:Main.java
/** * Is a dateTime after tomorrow/*from w w w . ja v a2 s .c o m*/ * @param dateTimeString in format 2012-10-15T08:17:00 * @return true if not today or tomorrow * */ public static String isAfterTomorrow(String dateTime) { Calendar depDate = parseCalendarString(dateTime); int month = depDate.get(Calendar.MONTH) + 1; int day = depDate.get(Calendar.DAY_OF_MONTH); return day + "/" + month; }
From source file:Main.java
/** * Returns the year (index 0), month (index 1) and day (index 2) of the given timestamp. * @param timestamp the timestamp//w ww . ja v a2s . c o m * @return the year (index 0), month (index 1) and day (index 2) of the given timestamp */ public static int[] getDayMonthYear(long timestamp) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTimeInMillis(timestamp); int day = gregorianCalendar.get(Calendar.DAY_OF_MONTH); int month = gregorianCalendar.get(Calendar.MONTH) + 1; int year = gregorianCalendar.get(Calendar.YEAR); return new int[] { year, month, day }; }
From source file:Util.java
public static String getFilesystemPathFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from www. java 2 s .com*/ NumberFormat format = new DecimalFormat("00"); return File.separator + format.format(calendar.get(Calendar.YEAR)) + File.separator + format.format((calendar.get(Calendar.MONTH) + 1)) + File.separator + format.format(calendar.get(Calendar.DAY_OF_MONTH)) + File.separator; }
From source file:Main.java
public static int getDayFromDate(String origDate) { DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); Date date;//from w w w . j av a 2 s.c o m int day = 1; try { date = formatter.parse(origDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); day = cal.get(Calendar.DAY_OF_MONTH); } catch (ParseException e) { e.printStackTrace(); } return day; }
From source file:Main.java
/** * returns 1 if calendar1 > calendar2 0 if calendar1 = calendar2 (same day, * month and year) -1 if calendar1 > calendar2 * /* w ww .j a va2s. co m*/ * @param calendar1 * @param calendar2 */ public static byte compareDay(Calendar calendar1, Calendar calendar2) { byte dayBefore = 0; int findDiff = 0;// dayBefore = compareMonth(calendar1, calendar2); if (dayBefore == 0) { findDiff = calendar1.get(Calendar.DAY_OF_MONTH) - calendar2.get(Calendar.DAY_OF_MONTH); if (findDiff > 0) { dayBefore = 1; } else if (findDiff < 0) { dayBefore = -1; } else { dayBefore = 0; } } return dayBefore; }
From source file:Main.java
public static String getCurrent() { Calendar calender = Calendar.getInstance(); String minute = ""; if (calender.get(Calendar.MINUTE) < 10) { minute = 0 + "" + calender.get(Calendar.MINUTE); } else {/* w w w . ja v a 2 s. co m*/ minute = "" + calender.get(Calendar.MINUTE); } String created = calender.get(Calendar.YEAR) % 100 + "/" + (calender.get(Calendar.MONTH) + 1) + "/" + calender.get(Calendar.DAY_OF_MONTH) + " " + calender.get(Calendar.HOUR_OF_DAY) + ":" + minute + ""; return created; }