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 long getEndOfMonthMs(int year, int month) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH)); date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
public static String convertToAge(String age) { String[] dates = age.split("-"); int year = Integer.parseInt(dates[0]); int currentYear = Calendar.getInstance().get(Calendar.YEAR); return (currentYear - year) + ""; }
From source file:Util.java
public static String formatAsMySQLDatetime(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w . ja va 2 s .c o m int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DATE); int hours = calendar.get(Calendar.HOUR_OF_DAY); int minutes = calendar.get(Calendar.MINUTE); int seconds = calendar.get(Calendar.SECOND); return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds; }
From source file:Main.java
public static boolean isAfterADay(Calendar newCalendar, Calendar oldCalendar) { Log.d("TEST", "run isAferDay"); if (newCalendar.get(Calendar.YEAR) > oldCalendar.get(Calendar.YEAR)) return true; if (newCalendar.get(Calendar.YEAR) == oldCalendar.get(Calendar.YEAR) && newCalendar.get(Calendar.MONTH) > oldCalendar.get(Calendar.MONTH)) return true; if (newCalendar.get(Calendar.YEAR) == oldCalendar.get(Calendar.YEAR) && newCalendar.get(Calendar.MONTH) == oldCalendar.get(Calendar.MONTH) && newCalendar.get(Calendar.DAY_OF_MONTH) > oldCalendar.get(Calendar.DAY_OF_MONTH)) return true; return false; }
From source file:Main.java
public static long getStartOfMonthMs(int year, int month) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, date.getActualMinimum(Calendar.DAY_OF_MONTH)); date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
public static int getYearOfDate(Date date) { calendar.setTime(date); return calendar.get(Calendar.YEAR); }
From source file:Main.java
public static int getYear() { long ts = System.currentTimeMillis(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(ts);/*from w ww . ja va 2 s . c om*/ return calendar.get(Calendar.YEAR); }
From source file:Main.java
public static boolean isYearSame(Calendar calendar, Calendar calendar2) { if (calendar == null || calendar2 == null) { return false; }// w w w . j a v a2s .c o m if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) { return true; } return false; }
From source file:Main.java
public static boolean isSameMonth(Calendar c1, Calendar c2) { if (c1 == null || c2 == null) return false; return (c1.get(Calendar.ERA) == c2.get(Calendar.ERA) && c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH)); }
From source file:Main.java
public static Calendar buildCalendarInstance(final int year, final int month, final int dayOfMonth) { final Calendar c = Calendar.getInstance(); c.clear();//from w w w .j a va2 s . c o m c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); return c; }