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 final void set(int year, int month, int date) 

Source Link

Document

Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.

Usage

From source file:Main.java

public static int getDayNumOfMonth(int y, int m) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(y, m - 1, 1);
    int dateNumber = calendar.getActualMaximum(Calendar.DATE);
    return dateNumber;
}

From source file:Main.java

/**
 * // ww w . j a v a2s.  c  o m
 * @param year
 * @param month
 * @param day
 * @return
 */
public static long getTimemillis(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(year, month, day);
    return cal.getTimeInMillis();
}

From source file:Main.java

private static Date getStartWeekOfMonth(int year, int month) {
    Calendar c = Calendar.getInstance();
    c.set(year, month - 1, 1);
    int week = c.get(Calendar.DAY_OF_WEEK);
    return getDistanceDate(c.getTime(), 1 - week);
}

From source file:Main.java

public static Calendar createCalendarDate(int year, int month, int dayOfMonth) {
    Calendar cal = Calendar.getInstance();
    cal.set(year, month, dayOfMonth);
    clearTime(cal);// w  w w  . j a  va2s  . c  o m
    return cal;
}

From source file:Main.java

@Deprecated
public static int getMonthOfMonth(int y, int m) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(y, m - 1, 1);
    int month = calendar.get(Calendar.MONTH);
    return month + 1;
}

From source file:Main.java

public static final String getStandardDate(int day, int month, int year) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, day);
    return format.format(calendar.getTime());
}

From source file:Main.java

/**
 * Get the number of rows for the provided month
 * @param year year/*from   w w  w  .  j  av  a2s . co m*/
 * @param month month
 * @return number of rows
 */
public static int getNumOfRowsForTheMonth(int year, int month, int startDayOfTheWeek) {
    Calendar cal = Calendar.getInstance();
    cal.set(year, month, 1);
    MonthDisplayHelper displayHelper = new MonthDisplayHelper(year, month, startDayOfTheWeek);
    return displayHelper.getRowOf(cal.getActualMaximum(Calendar.DAY_OF_MONTH)) + 1;
}

From source file:Main.java

/**
 * Get First Date of month//from  w w  w  .  j a va  2s  .c  o m
 */
public static Date getFirstDateOfMonth(int month, int year) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, 1);
    calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
    return calendar.getTime();
}

From source file:Main.java

public static Long createDate(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();

    calendar.set(year, month, day);

    return calendar.getTimeInMillis();

}

From source file:Main.java

public static Date parseDate(String dateString) {
    Matcher m = DATE_PATTERN.matcher(dateString.trim());
    if (!m.matches()) {
        throw new IllegalArgumentException("\"" + dateString + "\" must be in YYYY-MM-DD format.");
    }/*from ww w .  j a  v  a  2 s  .  co m*/
    Calendar c = Calendar.getInstance();
    c.set(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)) - 1, Integer.parseInt(m.group(3)));
    return c.getTime();
}