List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:Main.java
private static int dateCompareTo(Calendar calEnd, Calendar calStart) { if (calEnd.get(Calendar.DAY_OF_YEAR) == calStart.get(Calendar.DAY_OF_YEAR)) { if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) { return 0; } else {/*from w w w . j a va2 s.c om*/ if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) { return 1; } else { return -1; } } } else { if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) { if (calEnd.get(Calendar.DAY_OF_YEAR) > calStart.get(Calendar.DAY_OF_YEAR)) { return 1; } else { return -1; } } else if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) { return 1; } else { return -1; } } }
From source file:Main.java
public static Calendar getMorningCal(int hour, int minute) { Calendar c = Calendar.getInstance(); if (c.get(Calendar.HOUR_OF_DAY) > 3) { //next day c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) + 1); }/*from ww w .j av a 2 s . c o m*/ c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, 0); return c; }
From source file:Main.java
public static int daysOfTwo(Date fDate, Date oDate) { Calendar aCalendar = Calendar.getInstance(); aCalendar.setTime(fDate);//from ww w. j ava 2 s . com int day1 = aCalendar.get(Calendar.DAY_OF_YEAR); aCalendar.setTime(oDate); int day2 = aCalendar.get(Calendar.DAY_OF_YEAR); return day2 - day1; }
From source file:Main.java
public static boolean isToday(Calendar cal) { Calendar today = Calendar.getInstance(Locale.getDefault()); return cal.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == today.get(Calendar.YEAR); }
From source file:Main.java
public static boolean isTomorrow(Calendar cal) { Calendar tomorrow = Calendar.getInstance(Locale.getDefault()); tomorrow.roll(Calendar.DAY_OF_YEAR, true); return cal.get(Calendar.DAY_OF_YEAR) == tomorrow.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == tomorrow.get(Calendar.YEAR); }
From source file:Main.java
public static boolean isYesterday(Calendar cal) { Calendar yesterday = Calendar.getInstance(Locale.getDefault()); yesterday.roll(Calendar.DAY_OF_YEAR, false); return cal.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR); }
From source file:Main.java
public static int getCurWeekNum() { Calendar c = Calendar.getInstance(); c.setTime(new Date(System.currentTimeMillis())); int currentDayOfYear = c.get(Calendar.DAY_OF_YEAR) - 5; int distanceday; if (currentDayOfYear > 56 && currentDayOfYear < 244) { distanceday = currentDayOfYear - 56; } else if (currentDayOfYear > 244) { distanceday = currentDayOfYear - 244; } else {/*from w ww . j a v a2s . c om*/ return 0; } return distanceday / 7 + 1; }
From source file:Main.java
/** * Set the last day of the month/*from w w w . j av a 2s .c om*/ * @param c Calendar */ public static void setLastDayMonth(Calendar c) { c.add(Calendar.MONTH, 1); c.add(Calendar.DAY_OF_YEAR, -1); }
From source file:Main.java
public static boolean IsDiferentDate(Date date1, Date date2) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date1);/*ww w .j av a 2s.c o m*/ int daysInYear1 = calendar.get(Calendar.DAY_OF_YEAR); calendar = Calendar.getInstance(); calendar.setTime(date2); int daysInYear2 = calendar.get(Calendar.DAY_OF_YEAR); if (daysInYear1 != daysInYear2 || date1.getYear() != date2.getYear()) { return true; } return false; }
From source file:Main.java
public static Date datePlusNDay(Date date, int n) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);// w w w .j a va 2 s. com calendar.add(Calendar.DAY_OF_YEAR, n); return calendar.getTime(); }