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

private static void removeTimeFromCalendar(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);//from w  ww . j  av a2s .c  om
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static Calendar toBeginningOfDay(Calendar day) {
    day.set(Calendar.HOUR_OF_DAY, 0);
    day.set(Calendar.MINUTE, 0);// w w w  . j  a v  a 2 s.  c  o  m
    day.set(Calendar.SECOND, 0);
    day.set(Calendar.MILLISECOND, 0);
    return day;
}

From source file:Main.java

public static void setToFirstDayInMonth(Calendar calendar) {
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.getTimeInMillis();
}

From source file:Main.java

public static void setToFirstDayInWeek(Calendar calendar) {
    calendar.set(Calendar.DAY_OF_WEEK, 1);
    calendar.getTimeInMillis();
}

From source file:Main.java

/**
 * keep year, month & day of calendar
 *
 * @param c calendar to be clear/*  w ww . j  a va2s  .  c  om*/
 */
public static void clearCalendarOffset(Calendar c) {
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.HOUR_OF_DAY, 0);
}

From source file:Main.java

/**
 * Clean hours, minutes, seconds and milliseconds
 * @param c Calendar to clean/*from www . j  a v a2  s.  c  om*/
 */
public static void cleanDay(Calendar c) {
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static Calendar setEndOfDate(Calendar calendar) {
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);
    return calendar;
}

From source file:Main.java

/**
 * Convert the day in calendar in the end of the day: 23:59:59.999
 * @param c Calendar to change//from   w  w w .  j  a v  a2  s  .c  o  m
 */
public static void endOfDay(Calendar c) {

    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    c.set(Calendar.MILLISECOND, 999);
}

From source file:Main.java

public static void clearTime(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);// w  w w .  j a  v a  2s . c om
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

}

From source file:Main.java

public static Date round2Hour(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);// w ww.ja  v a2  s. c  o  m
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}