List of usage examples for java.util Calendar MONTH
int MONTH
To view the source code for java.util Calendar MONTH.
Click Source Link
get
and set
indicating the month. 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 String getMonth(Date date, boolean withZeroFill) { Calendar calendar = getCalendar(date); String month = (calendar.get(Calendar.MONTH) + 1) + ""; return (month.length() == 1 && withZeroFill) ? ("0" + month) : month; }
From source file:Main.java
public static LinkedHashMap<String, Integer> getDateMap(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);// www. j ava 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; }
From source file:Util.java
public static String getFilesystemPathFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from www . j av a2s . 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 Calendar getRandomDate(int baseYear) { synchronized (rand) { Calendar today = Calendar.getInstance(); int year = rand.nextInt(today.get(Calendar.YEAR) - baseYear + 1) + baseYear; int month = year == today.get(Calendar.YEAR) ? rand.nextInt(today.get(Calendar.MONTH) - 1) + 1 : rand.nextInt(12) + 1;// ww w.j a v a 2s . c om int day = year == today.get(Calendar.YEAR) ? rand.nextInt(today.get(Calendar.DAY_OF_WEEK)) + 1 : rand.nextInt(29) + 1; return new GregorianCalendar(year, month, day); } }
From source file:Main.java
public static boolean isDatesInSameMonth(long lhs, long rhs) { Calendar lhsCalendar = getCalendarWithTime(lhs); int lhsMonth = lhsCalendar.get(Calendar.MONTH); int lhsYear = lhsCalendar.get(Calendar.YEAR); Calendar rhsCalendar = getCalendarWithTime(rhs); int rhsMonth = rhsCalendar.get(Calendar.MONTH); int rhsYear = rhsCalendar.get(Calendar.YEAR); return (lhsMonth == rhsMonth) && (lhsYear == rhsYear); }
From source file:Main.java
/** * Liefert das Jahr in welchem das Semester begann. Dies ist besonders im Wintersemester nach dem Jahreswechsel wichtig * * @return Jahr in welchem das aktuelle Semester begann *///from w w w . j a va 2 s . c om public static int getStartYearOfSemester() { final Calendar calendar = GregorianCalendar.getInstance(); if (calendar.get(Calendar.MONTH) <= Calendar.FEBRUARY) return calendar.get(Calendar.YEAR) - 1; return calendar.get(Calendar.YEAR); }
From source file:Main.java
/** * @param days//www .ja va 2s . c o m * number of days after September 02, 1975 (what happened on this * day?) * @return */ public static Calendar getDayFromQuickLogEntry(int days) { Calendar logDay = GregorianCalendar.getInstance(); logDay.set(Calendar.DAY_OF_MONTH, 2); logDay.set(Calendar.MONTH, Calendar.SEPTEMBER); logDay.set(Calendar.YEAR, 1975); logDay.add(Calendar.DAY_OF_YEAR, days); return logDay; }
From source file:Main.java
/** * Is a dateTime after tomorrow//from www. ja v a 2s . c o m * @param dateTimeString in format 2012-10-15T08:17:00 * @return true if not today or tomorrow * */ public static String isAfterTomorrow(String dateTime) { Calendar depDate = parseCalendarString(dateTime); int month = depDate.get(Calendar.MONTH) + 1; int day = depDate.get(Calendar.DAY_OF_MONTH); return day + "/" + month; }
From source file:Main.java
public static boolean isCardExpired(String expiry, Date referenceDate) { boolean expired = false; int monthExpiry = Integer.parseInt(expiry.substring(0, 2)); int yearExpiry = 2000 + Integer.parseInt(expiry.substring(2, 4)); Calendar c = Calendar.getInstance(); c.setTime(referenceDate);/*from w w w .j a va2 s . c o m*/ int monthRef = c.get(Calendar.MONTH) + 1; // months indexed from 0 in java int yearRef = c.get(Calendar.YEAR); if (yearExpiry < yearRef) { expired = true; } else if (yearExpiry == yearRef && monthExpiry < monthRef) { expired = true; } return expired; }