Example usage for java.util Calendar DAY_OF_YEAR

List of usage examples for java.util Calendar DAY_OF_YEAR

Introduction

In this page you can find the example usage for java.util Calendar DAY_OF_YEAR.

Prototype

int DAY_OF_YEAR

To view the source code for java.util Calendar DAY_OF_YEAR.

Click Source Link

Document

Field number for get and set indicating the day number within the current year.

Usage

From source file:Main.java

public static boolean isTaday(Long time) {
    Calendar calendar_cur = Calendar.getInstance();
    Calendar calendar_old = Calendar.getInstance();
    calendar_old.setTimeInMillis(time);/* w w  w  .j a  v a  2s .  co m*/
    int day_cur = calendar_cur.get(Calendar.DAY_OF_YEAR);
    int day_old = calendar_old.get(Calendar.DAY_OF_YEAR);
    if (day_cur == day_old) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

public static int getDayOfYear(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from w w  w.ja va  2s  .c om
    return c.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static boolean isSameDayIgnoreYear(Date date1, Date date2) {
    Calendar cal1 = buildFromDate(date1);
    Calendar cal2 = buildFromDate(date2);
    return cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static boolean inSameDay(Date date1, Date Date2) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date1);//from w  w w .j  a  v a  2  s.  c o m
    int year1 = calendar.get(Calendar.YEAR);
    int day1 = calendar.get(Calendar.DAY_OF_YEAR);

    calendar.setTime(Date2);
    int year2 = calendar.get(Calendar.YEAR);
    int day2 = calendar.get(Calendar.DAY_OF_YEAR);

    return (year1 == year2) && (day1 == day2);
}

From source file:Main.java

public static Calendar getCalendarAtMidnight(int relativeDayToToday) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.add(Calendar.DAY_OF_YEAR, relativeDayToToday);
    return calendar;
}

From source file:Main.java

public static boolean isSameDate(Date date1, Date date2) {

    Calendar cal = Calendar.getInstance();
    cal.setTime(date1);/*from   w ww.  ja va 2  s .c o  m*/
    Calendar selectedDate = Calendar.getInstance();
    selectedDate.setTime(date2);

    return cal.get(Calendar.DAY_OF_YEAR) == selectedDate.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static boolean isTheSameDay(Date one, Date another) {
    Calendar _one = Calendar.getInstance();
    _one.setTime(one);//w ww  .j a v a 2  s  . co m
    Calendar _another = Calendar.getInstance();
    _another.setTime(another);
    int oneDay = _one.get(Calendar.DAY_OF_YEAR);
    int anotherDay = _another.get(Calendar.DAY_OF_YEAR);

    return oneDay == anotherDay;
}

From source file:Main.java

public static int isInSameDay(long day1, long day2) {
    Calendar c1 = Calendar.getInstance();
    c1.setTimeInMillis(day1);/*from  w w  w . j  a v a 2s.com*/
    Calendar c2 = Calendar.getInstance();
    c2.setTimeInMillis(day2);
    if (c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR))
        return 0;
    else {
        return c1.get(Calendar.DAY_OF_YEAR) > c2.get(Calendar.DAY_OF_YEAR) ? 1 : -1;
    }

}

From source file:Main.java

public static Date weekDayOfWeek(Date startWeekDate, int day) {
    Calendar calendar = Calendar.getInstance(Locale.GERMANY);
    calendar.setTime(startWeekDate);/*  ww  w  .  j a  v  a  2 s  .co m*/
    calendar.add(Calendar.DAY_OF_YEAR, day);

    return calendar.getTime();
}

From source file:Main.java

/**
 * Calculates the current day of the year and returns an int
 * @return Day - Day of the year. No time info.
 */// w  ww  .ja va 2  s.  co m
public static int getCurrentDay() {
    return Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
}