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 boolean isSameYear(Date targetTime, Date compareTime) { if (targetTime == null || compareTime == null) { return false; }//from w ww .j a v a 2s . c om Calendar tarCalendar = Calendar.getInstance(); tarCalendar.setTime(targetTime); int tarYear = tarCalendar.get(Calendar.YEAR); Calendar compareCalendar = Calendar.getInstance(); compareCalendar.setTime(compareTime); int comYear = compareCalendar.get(Calendar.YEAR); return tarYear == comYear; }
From source file:Main.java
public static java.util.Date getDateEnd(java.util.Date d) { Calendar c = Calendar.getInstance(); c.clear();/*from ww w . ja v a2 s . c om*/ Calendar co = Calendar.getInstance(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MILLISECOND, -1); return c.getTime(); }
From source file:Main.java
public static Bundle bundleCalendar(Calendar cal) { Bundle args = new Bundle(); if (cal == null) cal = Calendar.getInstance(Locale.getDefault()); ;//from w ww .j a v a 2s .c om args.putInt("year", cal.get(Calendar.YEAR)); args.putInt("month", cal.get(Calendar.MONTH)); args.putInt("day", cal.get(Calendar.DAY_OF_MONTH)); args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY)); args.putInt("minute", cal.get(Calendar.MINUTE)); return args; }
From source file:Main.java
public static boolean hasMonthPassed(int year, int month) { Calendar now = Calendar.getInstance(); // Expires at end of specified month, Calendar month starts at 0 return hasYearPassed(year) || normalizeYear(year) == now.get(Calendar.YEAR) && month < (now.get(Calendar.MONTH) + 1); }
From source file:Util.java
public static String getFilesystemPathFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/* w w w. ja va 2s.c o m*/ NumberFormat format = new DecimalFormat("00"); return File.separator + format.format(calendar.get(Calendar.YEAR)) + File.separator + format.format((calendar.get(Calendar.MONTH) + 1)) + File.separator + format.format(calendar.get(Calendar.DAY_OF_MONTH)) + File.separator; }
From source file:Main.java
public static long ArrivalMilliseconds(String arrivalTime) { Calendar calendarToday = Calendar.getInstance(); Calendar calendarTrainArrival = Calendar.getInstance(); long millisecondsTrainArrival; int nowYear = calendarToday.get(Calendar.YEAR); int nowMonth = calendarToday.get(Calendar.MONTH); int nowDay = calendarToday.get(Calendar.DATE); int evalhr = 0; int evalmin = 0; int evalsec = 0; String delims = "[:]"; String[] timesplit = arrivalTime.split(delims); evalhr = Integer.parseInt(timesplit[0]); //HR evalmin = Integer.parseInt(timesplit[1]); //MIN evalsec = Integer.parseInt(timesplit[2]); //SEC - VRE does not provide a schedule down to seconds, so ignore. calendarTrainArrival.set(nowYear, nowMonth, nowDay, evalhr, evalmin); millisecondsTrainArrival = calendarTrainArrival.getTimeInMillis(); return millisecondsTrainArrival; }
From source file:Main.java
public static boolean isTomorrow(Calendar cal) { Calendar tomorrow = Calendar.getInstance(Locale.getDefault()); tomorrow.roll(Calendar.DAY_OF_YEAR, true); return cal.get(Calendar.DAY_OF_YEAR) == tomorrow.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == tomorrow.get(Calendar.YEAR); }
From source file:Main.java
public static String getSemesterString() { Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); if (getSemester() == 0) { year = year % 100;// www .j ava 2 s .c o m int next_year = year + 1; return String.format(STRING_WINTER, year, next_year); } else { return String.format(STRING_SUMMER, year); } }
From source file:Main.java
public static boolean isYesterday(Calendar cal) { Calendar yesterday = Calendar.getInstance(Locale.getDefault()); yesterday.roll(Calendar.DAY_OF_YEAR, false); return cal.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR); }
From source file:Main.java
public static LinkedHashMap<String, Integer> getDateMap(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from w ww .ja v a 2 s. c om LinkedHashMap<String, Integer> datemap = new LinkedHashMap<String, Integer>(); datemap.put("year", cal.get(Calendar.YEAR)); datemap.put("month", cal.get(Calendar.MONTH)); datemap.put("day", cal.get(Calendar.DAY_OF_MONTH)); datemap.put("hour", cal.get(Calendar.HOUR_OF_DAY)); datemap.put("minute", cal.get(Calendar.MINUTE)); datemap.put("second", cal.get(Calendar.SECOND)); datemap.put("millisecond", cal.get(Calendar.MILLISECOND)); return datemap; }