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 GetLastYearRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    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 long timeInMillis(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, 0);

    long timeBefore = calendar.getTimeInMillis();

    if (Calendar.getInstance().getTimeInMillis() > timeBefore)
        calendar.add(Calendar.DAY_OF_WEEK, 1);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static String[] getShortWeekDays() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    String[] weekDays = new String[7];
    for (int i = 0; i < 7; i++) {
        weekDays[i] = SHORT_WEEK_DAYS_FORMAT.format(calendar.getTime());
        calendar.add(Calendar.DATE, 1);
    }/*from  w  w w .ja  v a 2s . com*/
    return weekDays;
}

From source file:Main.java

public static Calendar GetLastMonthLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    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.MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static long getCountDownDays(int dayMonth, int month, int year) {

    Calendar thatDay = Calendar.getInstance();
    thatDay.set(Calendar.DAY_OF_MONTH, dayMonth);
    thatDay.set(Calendar.MONTH, month - 1); // 0-11 so 1 less
    thatDay.set(Calendar.YEAR, year);

    Calendar today = Calendar.getInstance();
    long diff = thatDay.getTimeInMillis() - today.getTimeInMillis();

    return diff / (24 * 60 * 60 * 1000);

}

From source file:Main.java

public static void zeroFromHour(Calendar calendar) {
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static Calendar nextBirthday(Calendar today, Calendar dayOfBirth) {
    Calendar nextBirthday = (Calendar) dayOfBirth.clone();
    nextBirthday.set(Calendar.YEAR, today.get(Calendar.YEAR));
    if (nextBirthday.before(today)) {
        nextBirthday.add(Calendar.YEAR, 1);
    }/*from www .  j av a2 s.  c  om*/
    return nextBirthday;
}

From source file:Main.java

public static void trunkMonth(Calendar c) {
    trunkDay(c);
    c.set(Calendar.DAY_OF_MONTH, 1);
}

From source file:Main.java

public static long getEndOfMonthMs(int year, int month) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH));
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}

From source file:Main.java

public static long getEndOfDayMs(int year, int month, int day) {
    final Calendar date = Calendar.getInstance();

    date.set(Calendar.YEAR, year);
    date.set(Calendar.MONTH, month);
    date.set(Calendar.DAY_OF_MONTH, day);
    date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY));
    date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE));
    date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND));
    date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND));
    return date.getTimeInMillis();
}