Example usage for java.util Calendar get

List of usage examples for java.util Calendar get

Introduction

In this page you can find the example usage for java.util Calendar get.

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

From source file:Main.java

public static int getDayOfWeek(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//  www . jav  a2s.  c  o  m
    return c.get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

public static Date toNearestWholeMinute(Date d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d);//ww w . j  a  va2 s  . c o  m

    if (c.get(Calendar.SECOND) >= 30)
        c.add(Calendar.MINUTE, 1);

    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTime();
}

From source file:Main.java

public static int getDayOfYear() {
    final Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static int getMonthOfYear(Date time) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(time);/* w  w w .j ava  2 s.c o  m*/
    return calendar.get(Calendar.MONTH);
}

From source file:Main.java

public static String getSecond() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    int second = c.get(Calendar.SECOND);
    return Integer.toString(second);
}

From source file:Main.java

public static int getMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from   w w  w  . ja v a  2 s  . c o m*/
    return calendar.get(Calendar.MONTH);
}

From source file:Main.java

public static int getMinutes() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    int minute = c.get(Calendar.MINUTE);
    return minute;
}

From source file:Main.java

private static int dateCompareTo(Calendar calEnd, Calendar calStart) {
    if (calEnd.get(Calendar.DAY_OF_YEAR) == calStart.get(Calendar.DAY_OF_YEAR)) {
        if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) {
            return 0;
        } else {//from   w w  w.java  2 s .  com
            if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) {
                return 1;
            } else {
                return -1;
            }
        }
    } else {
        if (calEnd.get(Calendar.YEAR) == calStart.get(Calendar.YEAR)) {
            if (calEnd.get(Calendar.DAY_OF_YEAR) > calStart.get(Calendar.DAY_OF_YEAR)) {
                return 1;
            } else {
                return -1;
            }
        } else if (calEnd.get(Calendar.YEAR) > calStart.get(Calendar.YEAR)) {
            return 1;
        } else {
            return -1;
        }

    }
}

From source file:Main.java

/**
 * Get the weekday of the calendar//from ww  w  .j ava 2  s .  c  om
 * @param calendar
 * @return Weekday
 */
public static String getWeekDay(Calendar calendar) {
    return getDay(calendar.get(Calendar.DAY_OF_WEEK));
}

From source file:Main.java

public static int[] getYMD(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/* ww  w.  j ava2  s  .  com*/
    return new int[] { cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DATE) };
}