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 String getFirstDayOfMonth(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));
    return new SimpleDateFormat("yyyy-MM-dd ").format(cal.getTime());
}

From source file:Main.java

private static long getTodayZeroTime() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);/* w  ww .  jav  a  2 s.  c o  m*/
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static long firstOfTheMonth9am() {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.DAY_OF_MONTH, 1);
    c.set(Calendar.HOUR_OF_DAY, 9);
    c.set(Calendar.MINUTE, 0);//from   w  ww.  j  a  v a  2  s. com
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

From source file:Main.java

private static long getYesterdayZeroTime() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, -24);
    cal.set(Calendar.SECOND, 0);//from   w  w  w.  j  a  v a2 s . c  om
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static long date2long(int hour, int minute, int second) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 18);
    c.set(Calendar.MINUTE, 0);//from  w w w.  j  a v  a 2  s  .c om
    c.set(Calendar.SECOND, 0);
    Date d = c.getTime();
    return d.getTime();
}

From source file:Main.java

public static long getTimesEnd() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.MILLISECOND, 999);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static String updateCalendarTimeAndGetFormat(Calendar cal, int hourOfDay, int minute) {
    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    return defaultTimeFormat.format(cal.getTime());
}

From source file:Main.java

public static long getDayStart() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);//from   w  ww . j ava  2 s. c  o m
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static long getTimesStart() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.SECOND, 0);/*w w  w  . j  av a2  s .  c  om*/
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static int getMonthOfDays(int year, int month) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    return calendar.getActualMaximum(Calendar.DATE);
}