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 getWeekOfMonth() {
    Calendar calendar = Calendar.getInstance();
    int week = calendar.get(Calendar.WEEK_OF_MONTH);
    return week - 1;
}

From source file:Main.java

public static Integer GetDayOfMonth(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);/*from www.ja v a2 s  . c  o  m*/
    return cal.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static Calendar todaysCalendar() {
    Calendar now = Calendar.getInstance();
    return createNewCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
            now.get(Calendar.DAY_OF_MONTH));
}

From source file:Main.java

public static int getSeason(Calendar calendar) {
    int month = calendar.get(Calendar.MONTH) + 1;
    switch (month) {
    case 1:/*from ww w.j a  v a  2  s .  com*/
    case 11:
    case 12:
        return SEASON_SPRING;
    case 2:
    case 3:
    case 4:
        return SEASON_SUMMER;
    case 5:
    case 6:
    case 7:
        return SEASON_AUTUMN;
    case 8:
    case 9:
    case 10:
        return SEASON_WINTER;
    }
    return SEASON_SPRING;
}

From source file:Main.java

/**
 * Liefert das Jahr in welchem das Semester begann. Dies ist besonders im Wintersemester nach dem Jahreswechsel wichtig
 *
 * @return Jahr in welchem das aktuelle Semester begann
 *///w  w w. j a v a  2s. co m
public static int getStartYearOfSemester() {
    final Calendar calendar = GregorianCalendar.getInstance();
    if (calendar.get(Calendar.MONTH) <= Calendar.FEBRUARY)
        return calendar.get(Calendar.YEAR) - 1;
    return calendar.get(Calendar.YEAR);
}

From source file:Main.java

public static String getCurrentTime() {
    DecimalFormat df = new DecimalFormat("00");
    Calendar c = Calendar.getInstance();
    String currentTime = c.get(Calendar.YEAR)// + "-"
            + df.format((c.get(Calendar.MONTH) + 1)) // + "-"
            + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-"
            + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-"
            + df.format(c.get(Calendar.MINUTE))// + "-"
            + df.format(c.get(Calendar.SECOND));
    return currentTime;
}

From source file:Main.java

/**
 * Method to check if a date is this week. Note that it checks if it is this
 * week and not 7 days ahead!/*www.j av  a 2 s  .c  o m*/
 * 
 * @param theDate
 *            the date to see if it is this week
 * @return true if it is this week
 */
public static boolean isThisWeek(Date theDate) {
    // Get a calendar with the events start time
    GregorianCalendar theCalendar = new GregorianCalendar();
    theCalendar.setTime(theDate);
    // Get a calendar with current system time
    Calendar tmpDate = Calendar.getInstance();

    return tmpDate.get(Calendar.YEAR) == theCalendar.get(Calendar.YEAR)
            && tmpDate.get(Calendar.WEEK_OF_YEAR) == theCalendar.get(Calendar.WEEK_OF_YEAR);
}

From source file:Main.java

public static String getMonth(Date date, boolean withZeroFill) {
    Calendar calendar = getCalendar(date);
    String month = (calendar.get(Calendar.MONTH) + 1) + "";
    return (month.length() == 1 && withZeroFill) ? ("0" + month) : month;
}

From source file:Main.java

private static TimeZone guessTimeZone(Calendar c, String country) {
    return TimeUtils.getTimeZone(c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET),
            c.get(Calendar.DST_OFFSET) != 0, c.getTimeInMillis(), country);
}

From source file:Main.java

public static int getYear(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*  www .j  a  v  a  2 s.  c om*/
    return c.get(Calendar.YEAR);
}