Example usage for java.util Calendar set

List of usage examples for java.util Calendar set

Introduction

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

Prototype

public void set(int field, int value) 

Source Link

Document

Sets the given calendar field to the given value.

Usage

From source file:Main.java

public static Calendar getNotificationCalendarNextDate(int hour, int minute) {
    Calendar currentCalendar = Calendar.getInstance();
    currentCalendar.add(Calendar.DATE, 1);
    currentCalendar.set(Calendar.HOUR_OF_DAY, hour);
    currentCalendar.set(Calendar.MINUTE, minute);
    return currentCalendar;

}

From source file:Main.java

/**
 * Get next month first day/*from w w  w  .java 2s  . c  o  m*/
 */
public static int getNextMonthFirstDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, 1);
    lastDate.set(Calendar.DATE, 1);
    return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int daysSince(final long date) {
    final Calendar logDate = Calendar.getInstance();
    logDate.setTimeInMillis(date);//  w w  w  .  j a v  a 2 s  . c o m
    logDate.set(Calendar.SECOND, 0);
    logDate.set(Calendar.MINUTE, 0);
    logDate.set(Calendar.HOUR_OF_DAY, 0);
    final Calendar today = Calendar.getInstance();
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.HOUR_OF_DAY, 0);
    return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d);
}

From source file:Main.java

/**
 * Get last month end day/*from   w  w  w  .j av a  2  s  .  com*/
 */
public static int getLastMonthEndDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -1);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    return lastDate.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static void moveToCalendarMonth(Calendar cal, int month) {
    assertArgumentNotMinusNotZeroInteger("month", month);
    cal.set(Calendar.MONTH, month - 1); // zero origin headache
}

From source file:Main.java

/**
 * This method returns a new Date with a specified hour, minute, second and millis
 *
 * @param date/*from  w  w  w .j a va2 s  .co  m*/
 *         Start date
 * @param hourOfDay
 *         Target hour (0 - 23)
 * @param minute
 *         Target minute (0 - 59)
 * @param second
 *         Target second (0 - 59)
 * @param millis
 *         Target millis (0 - 999)
 *
 * @return The requested time
 */
public static Date setTime(Date date, int hourOfDay, int minute, int second, int millis) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, millis);
    return cal.getTime();
}

From source file:Main.java

/**
 * Get next month end day/* w  w  w . j a  v a  2 s .c om*/
 *
 * @return
 */
public static int getNextMonthEndDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, 1);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    return lastDate.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Date firstTimeOfWeek(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}

From source file:Main.java

public static Calendar createCalendar(int month, int dayOfMonth, int hour, int minute) {
    Calendar calendar = createCalendar(dayOfMonth, hour, minute);
    calendar.set(Calendar.MONTH, month);
    return calendar;
}

From source file:Main.java

static void setDate(Calendar cal, int month, int date, boolean endOfDay) {
    cal.clear();/*from   ww  w  .j  a  v  a2 s  .  c om*/
    cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);
    if (endOfDay) {
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
    } else {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
    }
}