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

/**
 * Same as the getCurrentDay() method but uses the passed in argument
 * as a long milliseconds timestamp to calculate vs a day object
 * @parma timestamp This is the time (in milliseconds from the epoch date)
 * used to calculate the current day of the year. (IE 365 = Dec 31st)
 * @return Day Day of the year based on timestamp.
 *///from  www  . ja  va  2  s .  com
public static Integer getCurrentDay(long timestamp) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timestamp);
    return cal.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static int getDatePart(long time, int part) {
    if (time <= 0)
        return 0;
    Calendar cal = Calendar.getInstance(Locale.getDefault());
    cal.setTimeInMillis(time);//from w  w  w.  j  a v a2 s .c  om
    return cal.get(part);
}

From source file:Main.java

public static int getWeekOfMonth() {
    return Calendar.getInstance().get(Calendar.DAY_OF_WEEK_IN_MONTH);
}

From source file:Main.java

/**
 * Format a time value for the programme list.
 * /*  ww w.j  av a  2s  . c  o m*/
 * @param time the time to format
 * @return the formatted time
 */
public static String formatTimeProgrammeList(Calendar time) {
    // TODO: 24 hour clock support
    int hour = time.get(Calendar.HOUR_OF_DAY);
    int minute = time.get(Calendar.MINUTE);
    String ampm = (hour < 12 ? "\n   AM" : "\n   PM");
    if (hour == 0)
        hour = 12;
    else if (hour > 12)
        hour -= 12;
    if (hour < 10 && minute < 10)
        return "  " + hour + ":0" + minute + ampm;
    else if (hour < 10)
        return "  " + hour + ":" + minute + ampm;
    else if (minute < 10)
        return " " + hour + ":0" + minute + ampm;
    else
        return " " + hour + ":" + minute + ampm;
}

From source file:Main.java

public static String week() {

    // Create calendar instance
    Calendar calendar = Calendar.getInstance();

    System.out.println("Current week of this month = " + calendar.get(Calendar.WEEK_OF_MONTH));

    System.out.println("Current week of this year = " + calendar.get(Calendar.WEEK_OF_YEAR));
    return "";

}

From source file:Main.java

public static int getWeekOfYear(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from   w  w  w. j a v a  2  s . c  o m
    return cal.get(Calendar.WEEK_OF_YEAR);
}

From source file:Main.java

public static Date getEndFinanacialDate(Date taxdate) {

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(taxdate);/*from  www .  ja v a2 s .c  o  m*/
    int yr = calendar.get(Calendar.YEAR);
    calendar.set(yr, 11, 31);
    taxdate = calendar.getTime();

    return taxdate;
}

From source file:Main.java

public static int getCurrentDay() {
    return Calendar.getInstance().get(Calendar.DATE);
}

From source file:Main.java

public static int calculateDayOfWeek(Date date) {
    final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.setTime(date);/*from   www  .j a  v  a  2s.c o  m*/
    return calendar.get(Calendar.DAY_OF_WEEK);
}

From source file:Main.java

public static int getWeekOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from  ww w  .  j av a 2 s.  com*/
    return cal.get(Calendar.WEEK_OF_MONTH);
}