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 getFirstDayOfWeek() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);//from w ww  .  j av  a2s. c o m
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
}

From source file:Main.java

public static int getDaysByYearMonth(int year, int month) {

    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);/*from ww w  .ja v a2s  .c om*/
    a.roll(Calendar.DATE, -1);
    return a.get(Calendar.DATE);
}

From source file:Main.java

public static Calendar getTodayAt(int hours) {
    Calendar today = Calendar.getInstance();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hours);
    return calendar;
}

From source file:Main.java

public static Date getLastDayOfYear() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
    return calendar.getTime();
}

From source file:Main.java

public static long getTimesmorning() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);/*from  w  w  w .j  a v  a 2  s. c  om*/
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static String getMonthLastDay() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    return dateFormat.format(calendar.getTime());
}

From source file:Main.java

public static long getTodayStartTime() {
    Calendar date = new GregorianCalendar();
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 1);
    return date.getTimeInMillis();
}

From source file:Main.java

public static int getWeekOfFirstDay(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    return calendar.get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

public static Calendar today() {
    Calendar date = new GregorianCalendar();
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date;/* w  ww  .ja v  a  2s.c  o m*/
}

From source file:Main.java

public static String getWeekDay(int position) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, position + 1);

    return calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault());
}