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

/**
 * the hour of hte day//  w w  w .ja v  a 2 s.  c  om
 *
 * @return
 */
private static int hourOfTheDay() {
    final Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.HOUR_OF_DAY);
}

From source file:Main.java

public static boolean isValidDate() {
    Calendar calendar = Calendar.getInstance();
    int hours = calendar.get(Calendar.HOUR_OF_DAY);
    if (hours > 7) {
        return true;
    }//from   w w w  .  j  av  a2s .c  o m
    return false;
}

From source file:Main.java

public static boolean isWorkTime() {
    Calendar calendar = Calendar.getInstance();
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    if (hour < 9 || hour > 19) {
        return false;
    }//from w  w  w  .  j ava  2s  .co m

    return true;
}

From source file:Main.java

public static String getNowDataForChart() {
    Calendar calendar = Calendar.getInstance();
    int month = calendar.get(Calendar.MONTH) + 1;
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    return month + "-" + day;
}

From source file:Main.java

public static String getToday() {
    Calendar calendar = Calendar.getInstance();
    int month = calendar.get(Calendar.MONTH) + 1;
    return calendar.get(Calendar.YEAR) + "-" + ((month < 10) ? "0" + month : "" + month) + "-"
            + calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int getCurrentSeason() {
    Calendar c = Calendar.getInstance();
    int month = c.get(Calendar.MONTH);
    if (month >= 0 && month < 3) {
        return 1;
    } else if (month > 3 && month < 6) {
        return 2;
    } else if (month > 6 && month < 9) {
        return 3;
    }/* ww w  .  j  a  v a2 s  . c  o  m*/
    return 4;
}

From source file:Main.java

public static String getCurrentHour() {
    Calendar calendar = Calendar.getInstance();
    int nHour = calendar.get(Calendar.HOUR_OF_DAY);
    if (nHour < 10)
        return "0" + Integer.toString(nHour);
    else/*  w ww. ja va 2s.  co m*/
        return Integer.toString(nHour);
}

From source file:Main.java

public static boolean isSameDay(Calendar a, Calendar b) {
    boolean res = false;
    if (a.get(Calendar.YEAR) == b.get(Calendar.YEAR)
            && a.get(Calendar.DAY_OF_YEAR) == b.get(Calendar.DAY_OF_YEAR)) {
        res = true;/*from  ww w .ja va  2  s.  c  om*/
    }
    return res;
}

From source file:Main.java

public static boolean isNationalDay() {
    Calendar calendar = Calendar.getInstance();
    int month = calendar.get(Calendar.MONTH) + 1;
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    if (month == 10 && day <= 7) {
        return true;
    }/*from  w ww  . j  a v  a2s  .c o m*/
    return false;
}

From source file:Main.java

/**
 * This method is used to generate random number between given range.
 */// w  ww  .  j a v a2 s  .  c om
public static long getRandomNumberBetween() {
    Calendar rightNow = Calendar.getInstance();
    long offset = rightNow.get(Calendar.ZONE_OFFSET) + rightNow.get(Calendar.DST_OFFSET);
    long sinceMidnight = (rightNow.getTimeInMillis() + offset) % (24 * 60 * 60 * 1000);
    return sinceMidnight;
}