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 setDateTime(long timeStamp, Calendar currentCalender, int i) {
    currentCalender.setTimeInMillis(timeStamp);
    currentCalender.set(Calendar.DATE, 1);
    currentCalender.set(Calendar.HOUR_OF_DAY, 0);
    currentCalender.set(Calendar.MINUTE, 0);
    currentCalender.set(Calendar.SECOND, 0);
    currentCalender.set(Calendar.MILLISECOND, 0);
    currentCalender.add(Calendar.DATE, i);
}

From source file:Main.java

/**
 * Get month days by year, month/*from  w w  w  . ja va  2  s  .c  o  m*/
 *
 * @param year
 * @param month
 * @return
 */
public static int getMonthDays(int year, int month) {
    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);
    a.roll(Calendar.DATE, -1);
    int maxDate = a.get(Calendar.DATE);
    return maxDate;
}

From source file:Util.java

/**
 * Utility for setting the time on a date.
 * @param date/*w  ww .  j  a  va 2s . com*/
 * @param h
 * @param m
 * @param s
 * @return the date with the time set
 */
public static Date setTime(Date date, int h, int m, int s) {
    if (date == null)
        return null;
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.HOUR, h);
    calendar.set(Calendar.MINUTE, m);
    calendar.set(Calendar.SECOND, s);
    return calendar.getTime();
}

From source file:Main.java

public static Calendar createCalendar(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);
    return calendar;
}

From source file:Main.java

public static String getNowTime(int i) {
    SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
    Date beginDate = new Date();
    Calendar date = Calendar.getInstance();
    date.setTime(beginDate);//w  ww.  jav  a 2s  .  co m
    date.set(Calendar.DATE, date.get(Calendar.DATE) - i);
    Date endDate = null;
    try {
        endDate = dft.parse(dft.format(date.getTime()));
        String format = dft.format(endDate);
        return format;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static long getTodayMills() {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);//from w w  w. j  a va2s .  c om
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis();
}

From source file:Main.java

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

From source file:com.liusoft.dlog4j.util.DateUtils.java

/**
 * //  w  ww  .  jav a 2 s.  c om
 * @param cal
 */
public static void resetTime(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static void moveToCalendarDay(Calendar cal, int day) {
    assertArgumentNotMinusNotZeroInteger("day", day);
    cal.set(Calendar.DAY_OF_MONTH, day);
}

From source file:Main.java

public static Date setDateTime(Date originalDate, int hour, int minute, int second) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);//from  w  w  w  .java 2 s  .c  o  m
    cal.set(Calendar.HOUR, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}