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 Calendar getMonday(Calendar calendar) {
    while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        calendar.add(Calendar.DATE, -1);
    }//from   w  w w .ja va 2s  . c  o  m

    return calendar;
}

From source file:Main.java

public static String getCurrentTimeSeconds(Calendar c) {
    int seconds = c.get(Calendar.SECOND);
    if (seconds < 10) {
        return "0" + seconds;
    } else {/*from  w  w  w. j a v a2 s. co m*/
        return "" + seconds;
    }
}

From source file:Main.java

public static boolean isSameOnlyDay(Calendar start, Calendar end) {
    return start.get(Calendar.DAY_OF_MONTH) == end.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

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

From source file:Main.java

public static boolean isAM(Calendar time) {
    return Calendar.AM == time.get(Calendar.AM_PM);
}

From source file:Main.java

private static void prepareCalendarStartsMonday(Calendar calendar) {
    if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == Calendar.SUNDAY) {
            calendar.add(Calendar.DATE, -6);
        } else {//from   w w  w .  j  a  va2  s.  c  om
            calendar.add(Calendar.DATE, -dayOfWeek + 2);
        }
    }
}

From source file:Main.java

public static boolean isSameDay(Calendar day1, Calendar day2) {
    return day1.get(Calendar.YEAR) == day2.get(Calendar.YEAR)
            && day1.get(Calendar.DAY_OF_YEAR) == day2.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static boolean is1erMai(Calendar calendar) {
    return calendar.get(Calendar.MONTH) == Calendar.MAY && calendar.get(Calendar.DATE) == 1;
}

From source file:Main.java

public static boolean isInSameDay(Calendar cl1, Calendar cl2) {
    if (cl1.get(Calendar.DAY_OF_YEAR) == cl2.get(Calendar.DAY_OF_YEAR)
            && cl1.get(Calendar.YEAR) == cl2.get(Calendar.YEAR)) {
        return true;
    }/*from   www.jav a 2s  .co m*/
    return false;
}

From source file:Main.java

public static boolean isSameDay(Calendar cal1, Calendar cal2) {
    return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
            && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);
}