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
public static boolean isSameDay(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date1);//w w w . j a v a 2s . c om cal2.setTime(date2); return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
public static boolean isSameDay(long lhs, long rhs) { Calendar lhsCal = Calendar.getInstance(); Calendar rhsCal = Calendar.getInstance(); lhsCal.setTimeInMillis(lhs);/* w w w . jav a2 s . c o m*/ rhsCal.setTimeInMillis(rhs); return (lhsCal.get(Calendar.YEAR) == rhsCal.get(Calendar.YEAR)) && (lhsCal.get(Calendar.DAY_OF_YEAR) == rhsCal.get(Calendar.DAY_OF_YEAR)); }
From source file:Main.java
public static Date beginOfTheDay(@NonNull Date date) { Calendar inputDate = Calendar.getInstance(); inputDate.setTime(date);// w w w .ja va 2s . c om Calendar resultDate = Calendar.getInstance(); resultDate.set(inputDate.get(Calendar.YEAR), inputDate.get(Calendar.MONTH), inputDate.get(Calendar.DAY_OF_YEAR)); return resultDate.getTime(); }
From source file:Main.java
/** * CPLC dates are counted in days starting from "1986-02-04" * // www . j a v a2 s . c om * @param cplcDateValue * @return */ public static Calendar getDateFromCPLCDateValue(int cplcDateValue) { GregorianCalendar startDay = new GregorianCalendar(1977, 11, 29); startDay.add(Calendar.DAY_OF_YEAR, cplcDateValue); return startDay; }
From source file:Main.java
public static String previousDateString(String dateString) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date myDate = dateFormat.parse(dateString); Calendar calendar = Calendar.getInstance(); calendar.setTime(myDate);// ww w . jav a2 s . com calendar.add(Calendar.DAY_OF_YEAR, -1); Date previousDate = calendar.getTime(); String result = dateFormat.format(previousDate); return result; }
From source file:Main.java
public static boolean isSameDay(long timestamp1, long timestamp2) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(new Date(timestamp1)); cal2.setTime(new Date(timestamp2)); boolean sameYear = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR); boolean sameDay = cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); return sameYear && sameDay; }
From source file:Main.java
public static int calculateDayDiffOfSameYear(Date targetTime, Date compareTime) { if (targetTime == null || compareTime == null) { return 0; }/*from w w w .j a va 2 s . c o m*/ Calendar tarCalendar = Calendar.getInstance(); tarCalendar.setTime(targetTime); int tarDayOfYear = tarCalendar.get(Calendar.DAY_OF_YEAR); Calendar compareCalendar = Calendar.getInstance(); compareCalendar.setTime(compareTime); int comDayOfYear = compareCalendar.get(Calendar.DAY_OF_YEAR); return tarDayOfYear - comDayOfYear; }
From source file:Main.java
public static int getDayOFYear(String date) { try {//from ww w . j av a 2s .c o m Date parse = yearFormat.parse(date); Calendar instance = Calendar.getInstance(); instance.setTime(parse); return instance.get(Calendar.DAY_OF_YEAR); } catch (ParseException e) { e.printStackTrace(); } return 0; }
From source file:Main.java
public static Long getYesterday() { Calendar yesterday = Calendar.getInstance(); yesterday.setTimeZone(TimeZone.getDefault()); yesterday.set(Calendar.SECOND, 0); yesterday.set(Calendar.MINUTE, 0); yesterday.set(Calendar.HOUR_OF_DAY, 1); yesterday.set(Calendar.MILLISECOND, 0); int day = yesterday.get(Calendar.DAY_OF_YEAR); yesterday.set(Calendar.DAY_OF_YEAR, day - 1); return yesterday.getTimeInMillis(); }
From source file:Main.java
public static long getYearStart() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);//w w w .j a va 2s . co m cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }