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 getDayOfMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//w  w  w .  java 2  s.  c  om
    return c.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int getMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*  w w  w .j  ava2s. c  om*/
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static int getCurrentYear() {
    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    return c.get(Calendar.YEAR);
}

From source file:Main.java

public static int getDayOfYear(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from   w  w w  .j av  a  2  s . c  o  m
    return c.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static String getCurrentTimeStampHHMM() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2);
}

From source file:Main.java

public static String getCurrentTime() {
    Calendar calendar = Calendar.getInstance();
    return getToday() + " " + calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE);
}

From source file:Main.java

public static int getWeekOfDate(Date dt) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(dt);//from   ww  w .  jav  a2  s.  c  o  m
    int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
    return w < 0 ? 0 : w;
}

From source file:Main.java

public static String getCurrentTimeStampYYYY() {
    Calendar cal = new GregorianCalendar();
    return makeTimeString(cal.get(Calendar.YEAR), 4);
}

From source file:Util.java

private static boolean isMidnight(Calendar calendar) {
    return (calendar.get(Calendar.HOUR_OF_DAY) == 0) && (calendar.get(Calendar.MINUTE) == 0);
}

From source file:Main.java

public static Integer GetDayOfWeekNumber(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);/*  w  w  w . j  ava  2s. c o  m*/
    return cal.get(Calendar.DAY_OF_WEEK);
}