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

/**
 * @return Return current day timestamp with YY, MM, dd info ONLY
 *///from   w  w w  .  ja  v a  2s  . com
public static Long getCurrentDayTS() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static int getDay(int y, int m, int d) {
    if (m < 0 || m > 11)
        return -1;

    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, y);
    c.set(Calendar.MONTH, m);/*  w w  w .j a  va2 s.co  m*/
    c.set(Calendar.DATE, d);
    return c.get(Calendar.DAY_OF_WEEK) - 1;

}

From source file:Main.java

public static final String getStandardTime(int minute, int hour) {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.CHINA);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    return format.format(calendar.getTime());
}

From source file:Main.java

public static Date getDateFromYearMonthDay(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*ww  w .j  a  v  a  2s . c  om*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static long getStartOfCurrentYear() {
    Calendar calendar = getCurrentCalendar();
    calendar.set(Calendar.MONTH, 0);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static Date getDate(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*  w  w w .j a  v  a  2 s .  com*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static long getStartOfCurrentMonth() {
    Calendar calendar = getCurrentCalendar();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static long getEndOfCurrentYear() {
    Calendar calendar = getCurrentCalendar();
    calendar.set(Calendar.MONTH, 11);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static long getEndOfCurrentMonth() {
    Calendar calendar = getCurrentCalendar();
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static int[] getWeekSunday(int year, int month, int day, int pervious) {
    int[] time = new int[3];
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);
    c.add(Calendar.DAY_OF_MONTH, pervious);
    time[0] = c.get(Calendar.YEAR);
    time[1] = c.get(Calendar.MONTH) + 1;
    time[2] = c.get(Calendar.DAY_OF_MONTH);
    return time;/* ww  w. ja v  a 2  s.  c o  m*/

}