List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:Main.java
public static int getYears(int year, int month, int day) { GregorianCalendar cal = new GregorianCalendar(); int y, m, d, noofyears; y = cal.get(Calendar.YEAR);// current year , m = cal.get(Calendar.MONTH);// current month d = cal.get(Calendar.DAY_OF_MONTH);//current day cal.set(year, month, day);// here ur date noofyears = y - cal.get(Calendar.YEAR); if ((m < cal.get(Calendar.MONTH)) || ((m == cal.get(Calendar.MONTH)) && (d < cal.get(Calendar.DAY_OF_MONTH)))) { --noofyears;/*from ww w .ja v a 2s.c om*/ } try { if (noofyears < 0) throw new IllegalArgumentException("age < 0"); } catch (IllegalArgumentException ile) { ile.printStackTrace(); } System.out.println(noofyears); return noofyears; }
From source file:Main.java
public static String getYearStringFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);// w w w . j av a 2 s . co m StringBuilder sb = new StringBuilder("Year ").append(calendar.get(Calendar.YEAR)); return sb.toString(); }
From source file:Main.java
public static Integer getYear(Date date) { if (date == null) return 0; Calendar cal = Calendar.getInstance(); cal.setTime(date);/*w w w. j a va 2s .co m*/ return cal.get(Calendar.YEAR); }
From source file:Main.java
public static long betweenYear(String t1, String t2, String... patterns) { return betweenTime(Calendar.YEAR, t1, t2, patterns); }
From source file:Main.java
static float getDatePlg() { Calendar c = new GregorianCalendar(); int y = c.get(Calendar.YEAR); int m = 1 + c.get(Calendar.MONTH); int d = c.get(Calendar.DAY_OF_MONTH); return getDatePlg(y, m, d); }
From source file:Main.java
public static long betweenMonth(String t1, String t2, String... patterns) { return betweenTime(Calendar.YEAR, t1, t2, patterns) * 12 + betweenTime(Calendar.MONTH, t1, t2, patterns); }
From source file:Main.java
public static boolean areSameDay(Calendar c1, Calendar c2) { if (c1 == null || c2 == null) { return false; }//from ww w .j a v a2 s . co m int y1, y2, d1, d2; y1 = c1.get(Calendar.YEAR); y2 = c2.get(Calendar.YEAR); d1 = c1.get(Calendar.DAY_OF_YEAR); d2 = c2.get(Calendar.DAY_OF_YEAR); if (y1 == y2 && d1 == d2) { return true; } return false; }
From source file:Main.java
public static boolean isSameDay(Date date1, Date date2) { Calendar cal1 = buildFromDate(date1); Calendar cal2 = buildFromDate(date2); return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
public static String dataHoje() { Integer dia, mes, ano;//from ww w. j a va2 s .c om Calendar calendario = Calendar.getInstance(); dia = calendario.get(Calendar.DAY_OF_MONTH); mes = calendario.get(Calendar.MONTH); ano = calendario.get(Calendar.YEAR); return dia + "/" + (mes + 1) + "/" + ano; }
From source file:Main.java
/** * * @param c1/* w ww . j av a2 s . c o m*/ * @param c2 * @return */ public static boolean isSameMonth(Calendar c1, Calendar c2) { return !(c1 == null || c2 == null) && (c1.get(Calendar.ERA) == c2.get(Calendar.ERA) && (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) && (c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH))); }