Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:Main.java

public static boolean is1erMai(Calendar calendar) {
    return calendar.get(Calendar.MONTH) == Calendar.MAY && calendar.get(Calendar.DATE) == 1;
}

From source file:Main.java

public static Date startOfNextDay(Date origDate) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(origDate);/*w ww  .ja  v  a  2s.  c om*/
    cal.add(Calendar.DATE, 1);

    return startOfDay(cal.getTime());
}

From source file:Main.java

public static Date startOfThisMonth(int startDayOfMonth) {
    Calendar cal = Calendar.getInstance();

    if (cal.get(Calendar.DATE) < startDayOfMonth) // the start is startDayOfMonth, last month
        cal.add(Calendar.MONTH, -1);

    int lastDayInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

    if (startDayOfMonth <= lastDayInMonth)
        cal.set(Calendar.DATE, startDayOfMonth);
    else {//from  w w w  .ja  v  a2  s .  com
        cal.add(Calendar.MONTH, 1);
        cal.set(Calendar.DATE, 1);
    }

    return startOfDay(cal.getTime());
}

From source file:Main.java

public static Date startOfNextMonth(int startDayOfMonth) {
    Calendar cal = Calendar.getInstance();

    if (cal.get(Calendar.DATE) >= startDayOfMonth)// the end is one day past startDayOfMonth, next month
        cal.add(Calendar.MONTH, 1);

    int lastDayInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

    if (startDayOfMonth < lastDayInMonth)
        cal.set(Calendar.DATE, startDayOfMonth + 1);
    else {/* w  w  w  .  j ava2  s.c  o  m*/
        cal.add(Calendar.MONTH, 1);
        cal.set(Calendar.DATE, 1);
    }

    return startOfDay(cal.getTime());
}

From source file:Main.java

/**
 * Checks for the given calendar is in coming 7 days
 * @param calendar/*from ww  w.  j  ava  2  s  .c om*/
 * @return true if given calendar is in coming week
 */
public static boolean isComingWeek(Calendar calendar) {
    boolean flag = false;
    Calendar calendar2 = Calendar.getInstance();
    calendar2.add(Calendar.DATE, 7);
    if (calendar.before(calendar2)) {
        flag = true;
    }
    return flag;
}

From source file:Util.java

public static Date getMonday(Date today) {
    Calendar cal = Calendar.getInstance();

    cal.setTime(today);/*from w w  w  .j  ava 2  s  .  c  om*/

    int dow = cal.get(Calendar.DAY_OF_WEEK);

    while (dow != Calendar.MONDAY) {
        int date = cal.get(Calendar.DATE);

        if (date == 1) {
            int month = cal.get(Calendar.MONTH);

            if (month == Calendar.JANUARY) {
                month = Calendar.DECEMBER;

                cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) - 1);
            } else {
                month--;
            }

            cal.set(Calendar.MONTH, month);

            date = getMonthLastDate(month, cal.get(Calendar.YEAR));
        } else {
            date--;
        }

        cal.set(Calendar.DATE, date);

        dow = cal.get(Calendar.DAY_OF_WEEK);
    }

    return cal.getTime();
}

From source file:com.tinypace.mobistore.util.DateUtils.java

/** 
  * ? //from  w w w  . j  av  a 2  s.  c  om
  *  
  * @param d 
  * @param day 
  * @return 
  */
public static Date getDateBefore(Date d, int day) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) - day);
    return cal.getTime();
}

From source file:Main.java

/**
 * Converts input time from Java to DOS format
 * @param time/*  w ww  .ja  va 2  s . c o  m*/
 * @return time in DOS format 
 */
public static long javaToDosTime(long time) {

    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);

    int year = cal.get(Calendar.YEAR);
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (cal.get(Calendar.MONTH) + 1) << 21 | cal.get(Calendar.DATE) << 16
            | cal.get(Calendar.HOUR_OF_DAY) << 11 | cal.get(Calendar.MINUTE) << 5
            | cal.get(Calendar.SECOND) >> 1;
}

From source file:Main.java

/**
 * Get month days by year, month//from  w w  w . j  a v  a2s. c  om
 *
 * @param year
 * @param month
 * @return
 */
public static int getMonthDays(int year, int month) {
    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);
    a.roll(Calendar.DATE, -1);
    int maxDate = a.get(Calendar.DATE);
    return maxDate;
}

From source file:com.bjond.utilities.DateTimeUtils.java

/**
 * Returns 11:59:59.999 PM of date.//from  w w  w  .  j ava 2  s. c  o m
 *
 * @param date Valid non-null java.util.Date object.
 * @return New date. Original is not altered.
 */
public static Date getEndOfDay(final Date date) {
    return DateUtils.addMilliseconds(DateUtils.ceiling(date, Calendar.DATE), -1);
}