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 long startOfTodDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date date = calendar.getTime();
    return date.getTime();
}

From source file:Main.java

public static Calendar GetTodayLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar tomorrow() {
    Calendar tomorrow = new GregorianCalendar();
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);
    tomorrow.add(Calendar.DAY_OF_MONTH, 1);
    return tomorrow;
}

From source file:Main.java

public static Calendar GetTodayRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar getNotificationCalendarDate(int hour, int minute) {
    Calendar currentCalendar = Calendar.getInstance();
    currentCalendar.set(Calendar.HOUR_OF_DAY, hour);
    currentCalendar.set(Calendar.MINUTE, minute);
    return currentCalendar;

}

From source file:Main.java

public static long endOfThisMonth() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    cal.add(Calendar.MONTH, 1);/*from   w w w. j  a  v a 2s . c  o  m*/
    cal.add(Calendar.DATE, -1);
    Date date = cal.getTime();
    return date.getTime();
}

From source file:Main.java

public static String formatSimpleDateStr(int year, int monthOfYear, int dayOfMonth) {

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, monthOfYear);
    cal.set(Calendar.DATE, dayOfMonth);

    return SIMPLE_DATE_FORMAT.format(cal.getTime());
}

From source file:Main.java

public static Date moveToToday(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/* www.  j a  v a2s  .  co  m*/
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);

    Calendar result = Calendar.getInstance();
    result.set(Calendar.HOUR_OF_DAY, hour);
    result.set(Calendar.MINUTE, minute);
    return result.getTime();
}

From source file:Main.java

public static Date endOfThisMonth() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
    calendar.set(Calendar.HOUR, calendar.getActualMaximum(Calendar.HOUR));
    calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));

    return calendar.getTime();
}

From source file:Main.java

public static Calendar GetYesterdayLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}