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 void moveToCalendarWeekOfYear(Calendar cal, int weekOfYear) {
    assertArgumentNotMinusInteger("weekOfYear", weekOfYear);
    cal.set(Calendar.WEEK_OF_YEAR, weekOfYear);
}

From source file:Main.java

public static Calendar createCalendar(int year, int month, int dayOfMonth, int hour, int minute) {
    Calendar calendar = createCalendar(month, dayOfMonth, hour, minute);
    calendar.set(Calendar.YEAR, year);
    return calendar;
}

From source file:DateTimeUtil.java

/**
 * /*from  w  w w . j  a  v a2 s. co  m*/
 * @param month
 * @param year
 * @return
 */
public static final int getlastDateofThisMonth(int month, int year) {
    Calendar calendar = Calendar.getInstance();
    if (year > -1) {
        calendar.set(Calendar.YEAR, year);
    }

    if (month > -1) {
        month--;
        calendar.set(Calendar.MONTH, month);
    }

    return calendar.getActualMaximum(Calendar.DATE);
}

From source file:Main.java

public static void moveToCalendarWeekOfMonth(Calendar cal, int weekOfMonth) {
    assertArgumentNotMinusInteger("weekOfMonth", weekOfMonth);
    cal.set(Calendar.WEEK_OF_MONTH, weekOfMonth);
}

From source file:Main.java

public static Long getYesterday() {
    Calendar yesterday = Calendar.getInstance();
    yesterday.setTimeZone(TimeZone.getDefault());

    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.HOUR_OF_DAY, 1);
    yesterday.set(Calendar.MILLISECOND, 0);

    int day = yesterday.get(Calendar.DAY_OF_YEAR);

    yesterday.set(Calendar.DAY_OF_YEAR, day - 1);

    return yesterday.getTimeInMillis();
}

From source file:com.qpark.eip.core.spring.auth.LimitedAccessDataProvider.java

/**
 * Get a {@link Date}, where hours, minutes, seconds and milliseconds are
 * set to 0./*from   w w  w  .  j av  a 2s  .  c  om*/
 *
 * @return the {@link Date} and the corresponding log string.
 */
private static SimpleEntry<Date, String> getRequestDate() {
    Calendar gc = new GregorianCalendar();
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    String hmss = String.format("%04d%02d%02d", gc.get(Calendar.YEAR), gc.get(Calendar.MONTH) + 1,
            gc.get(Calendar.DAY_OF_MONTH));
    SimpleEntry<Date, String> entry = new SimpleEntry<Date, String>(gc.getTime(), hmss);
    return entry;
}

From source file:Main.java

public static Calendar getMorningCal(int hour, int minute) {
    Calendar c = Calendar.getInstance();
    if (c.get(Calendar.HOUR_OF_DAY) > 3) {
        //next day
        c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) + 1);
    }/*from w w w . j a  v  a  2  s.  c om*/
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, 0);

    return c;
}

From source file:Main.java

public static String formatDate(String date, int minutes) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date d = null;//from  www .jav  a2s  .c o  m
    try {
        d = sdf.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(d);
    calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - minutes);
    return sdf.format(calendar.getTime());
}

From source file:Main.java

public static Date getDifferenceDaysDate(long times, int diffDay) {
    Calendar now = Calendar.getInstance();
    Date d = new Date();
    d.setTime(times);/*from ww  w.  jav  a2 s  . c om*/
    now.setTime(d);
    now.set(Calendar.DATE, now.get(Calendar.DATE) + diffDay);
    return now.getTime();
}

From source file:Main.java

/**
 * Get the displayable date from week and year
 * @param week week of year/*from w w  w  .j av  a 2 s  .c o m*/
 * @param year year
 * @return Date string for displaying
 */
public static String getDate(int week, int year) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
    Calendar cal = Calendar.getInstance();
    //        Log.i(TAG, sdf.format(cal.getTime()));
    cal.set(Calendar.YEAR, year);
    //        Log.i(TAG, sdf.format(cal.getTime()));
    cal.set(Calendar.WEEK_OF_YEAR, week);
    //        Log.i(TAG, sdf.format(cal.getTime()));
    cal.set(Calendar.DAY_OF_WEEK, 1);
    //        Log.i(TAG, sdf.format(cal.getTime()));
    String start = sdf.format(cal.getTime());
    cal.set(Calendar.DAY_OF_WEEK, 7);
    //        Log.i(TAG, sdf.format(cal.getTime()));
    String end = sdf.format(cal.getTime());
    return start + " to " + end;
}