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() 

Source Link

Document

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

Usage

From source file:Main.java

public static int getMonth(int year, int week) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.WEEK_OF_YEAR, week);
    return calendar.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static int getWeekFromDay(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    calendar.set(Calendar.DAY_OF_MONTH, day);
    return calendar.get(Calendar.WEEK_OF_YEAR);
}

From source file:Main.java

public static int getDays(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month - 1);
    int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    return days;//  www  . j a va  2s .co  m
}

From source file:Main.java

public static java.util.Date getDateEnd(java.util.Date d) {
    Calendar c = Calendar.getInstance();
    c.clear();
    Calendar co = Calendar.getInstance();
    co.setTime(d);//w  w w.  j av  a2s .com
    c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH));
    c.set(Calendar.MONTH, co.get(Calendar.MONTH));
    c.set(Calendar.YEAR, co.get(Calendar.YEAR));
    c.add(Calendar.DAY_OF_MONTH, 1);
    c.add(Calendar.MILLISECOND, -1);
    return c.getTime();
}

From source file:Main.java

public static Calendar buildCalendarInstance(final int year, final int month, final int dayOfMonth) {
    final Calendar c = Calendar.getInstance();
    c.clear();

    c.set(Calendar.YEAR, year);/*from  w w  w . java 2s.co  m*/
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, dayOfMonth);

    return c;
}

From source file:Main.java

public static Calendar getTodayAt(int hours, int minutes) {
    Calendar today = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();
    cal.clear();

    int year = today.get(Calendar.YEAR);
    int month = today.get(Calendar.MONTH);
    //represents the day of the month
    int day = today.get(Calendar.DATE);
    cal.set(year, month, day, hours, minutes, 0);
    return cal;//  w  w w  .j  ava 2  s .  co m
}

From source file:Main.java

public static java.util.Date getDateStart(java.util.Date d) {

    Calendar c = new GregorianCalendar();
    c.clear();
    Calendar co = new GregorianCalendar();
    co.setTime(d);//  ww w.  j a  va2 s .com
    c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH));
    c.set(Calendar.MONTH, co.get(Calendar.MONTH));
    c.set(Calendar.YEAR, co.get(Calendar.YEAR));
    // c.add(Calendar.DAY_OF_MONTH,1);
    // c.add(Calendar.MILLISECOND,-1);
    return c.getTime();
}

From source file:Main.java

public static Calendar getTomorrowAt(int hours, int minutes) {
    Calendar today = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();
    cal.clear();

    int year = today.get(Calendar.YEAR);
    int month = today.get(Calendar.MONTH);
    //represents the day of the month
    today.add(Calendar.DATE, 1);//  w  w w. ja  v a  2s . c  o m
    int day = today.get(Calendar.DATE);
    cal.set(year, month, day, hours, minutes, 0);
    return cal;
}

From source file:Main.java

static void setDate(Calendar cal, int month, int date) {
    cal.clear();

    cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from   w w w . ja  v a2 s . c o m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

/**
 * Returns Epoch date, ie. 01/01/1970.//from  ww w  .  j a v  a 2 s .c om
 *
 * @return Epoch date, ie. 01/01/1970.
 */
public static Date getEpoch() {
    final Calendar calendar = Calendar.getInstance();

    calendar.clear();
    calendar.set(1970, 0, 1);

    return calendar.getTime();
}