Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

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

Prototype

public final void clear(int field) 

Source Link

Document

Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    boolean b = cal.isSet(Calendar.DAY_OF_MONTH);
    System.out.println("Day of month is set: " + b);

    // clear day of month
    cal.clear(Calendar.DAY_OF_MONTH);

    // determine if the given calendar field has a value set
    b = cal.isSet(Calendar.DAY_OF_MONTH);
    System.out.println("Day of month is set: " + b);
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // display the current date and time
    System.out.println("Current Calendar Date: " + cal.getTime());

    // use clear method to set year as undefined.
    cal.clear(Calendar.YEAR);

    // print the result
    System.out.println("The calendar shows : " + cal.getTime());

    // use clear method to set month as undefined.
    cal.clear(Calendar.MONTH);/*from w w w . ja  v a 2  s.com*/

    System.out.println("The calendar shows : " + cal.getTime());
}

From source file:Main.java

public static Calendar clearTime(Calendar calendar) {
    calendar.clear(Calendar.HOUR_OF_DAY);
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);

    return calendar;
}

From source file:Main.java

public static long getBeginOfCurrentDateInMillis() {
    Calendar calendar = Calendar.getInstance();
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.HOUR_OF_DAY);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static Calendar clear(Calendar calendar, int... fields) {
    for (int field : fields) {
        calendar.clear(field);
    }/*from  w ww  . j a va2s  .com*/
    return calendar;
}

From source file:Main.java

public static List<Integer> getAllDayInMonth(int month, int year) {
    List<Integer> listDate = new ArrayList<Integer>();

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, 1);/*w  w  w.  ja  v a  2 s  .c om*/
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    int totalDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

    for (int i = 1; i <= totalDays; i++) {
        listDate.add(i);
    }
    return listDate;
}

From source file:Main.java

public static void toBeginOfDay(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.SECOND);/*from  w ww  .  ja  v a 2s .co  m*/
    cal.clear(Calendar.MILLISECOND);
}

From source file:Main.java

public static long getStartOfWeek(long week) {
    Calendar calendar = getCalendarWithTime(week);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);

    // get start of this week in milliseconds
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());

    return calendar.getTimeInMillis();
}

From source file:org.catrobat.jira.adminhelper.helper.HelperUtil.java

public static Date clearTime(final Date date) {
    Calendar beginCalendar = new GregorianCalendar();
    beginCalendar.setTime(date);//from   ww w.  ja va  2 s.c o m
    beginCalendar.set(Calendar.HOUR_OF_DAY, 0);
    beginCalendar.clear(Calendar.MINUTE);
    beginCalendar.clear(Calendar.SECOND);
    beginCalendar.clear(Calendar.MILLISECOND);

    return beginCalendar.getTime();
}

From source file:org.springframework.session.data.codis.CodisSessionExpirationPolicy.java

static long roundDownMinute(long timeInMs) {
    Calendar date = Calendar.getInstance();
    date.setTimeInMillis(timeInMs);/*from w  w w  .j a  v a  2s .  c o  m*/
    date.clear(Calendar.SECOND);
    date.clear(Calendar.MILLISECOND);
    return date.getTimeInMillis();
}