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
/** * Using the expiry date, generate the application end date in the correct format. * * @param expiryMonth Month of expiry./*from w ww .j av a 2 s . c o m*/ * @param expiryYear Year of expiry. * @return The application end date in the correct format. */ private static String generateExpiryDate(String expiryMonth, String expiryYear) { // Just combine the year and month String applicationEndDate = expiryYear + expiryMonth; // Now need to work out the last day of the month // NB: Calendar's months range from 0-11 rather than 1-12 Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, Integer.parseInt(expiryYear)); calendar.set(Calendar.MONTH, Integer.parseInt(expiryMonth) - 1); applicationEndDate += calendar.getActualMaximum(Calendar.DATE); return applicationEndDate; }
From source file:Main.java
/** * * This method is a utility method to create a new java.sql.Date in one line. * * @param year/*from w ww. j a v a 2 s .co m*/ * @param month * @param day * * @return a populated java.sql.Date with the year, month, and day specified, and no values for hour, minute, second, * millisecond * */ public static java.sql.Date newDate(Integer year, Integer month, Integer day) { // test for null arguments if (year == null) { throw new IllegalArgumentException("Argument 'year' passed in was null."); } if (month == null) { throw new IllegalArgumentException("Argument 'month' passed in was null."); } if (day == null) { throw new IllegalArgumentException("Argument 'day' passed in was null."); } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.clear(Calendar.HOUR_OF_DAY); calendar.clear(Calendar.MINUTE); calendar.clear(Calendar.SECOND); calendar.clear(Calendar.MILLISECOND); return new java.sql.Date(calendar.getTimeInMillis()); }
From source file:Main.java
public static File getEmptyFileWithStructuredPath(String course_title, String format) { Calendar calendar = Calendar.getInstance(); int date = calendar.get(Calendar.DATE); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); StringBuffer dateInString = new StringBuffer(); dateInString.append(month);/* w w w.j a v a 2s. co m*/ dateInString.append("-"); dateInString.append(date); dateInString.append("-"); dateInString.append(year); StringBuffer timeInString = new StringBuffer(); timeInString.append(hour); timeInString.append("_"); timeInString.append(minute); timeInString.append("_"); timeInString.append(second); Log.d("File Storage", "DateTime : " + dateInString + timeInString); String folderPathInString = Environment.getExternalStorageDirectory().toString() + "/" + LECTURE_HELPER + "/" + course_title + "/" + dateInString + "/"; File folderPath = new File(folderPathInString); if (!folderPath.exists()) { folderPath.mkdirs(); } return new File(folderPath.getPath() + "/" + FILE_NAME_TO_SAVE + timeInString + format); }
From source file:com.westlinkin.android_feedback_helper.utils.MailUntils.java
private static String getFeedbackNumber() { Calendar calendar = Calendar.getInstance(); return "" + calendar.get(Calendar.YEAR) + Utils.formatCalendarIntValue((calendar.get(Calendar.MONTH) + 1), 2) + Utils.formatCalendarIntValue(calendar.get(Calendar.DAY_OF_MONTH), 2) + "-" + Utils.formatCalendarIntValue(calendar.get(Calendar.HOUR_OF_DAY), 2) + Utils.formatCalendarIntValue(calendar.get(Calendar.MINUTE), 2) + Utils.formatCalendarIntValue(calendar.get(Calendar.SECOND), 2) + "-" + Utils.formatCalendarIntValue(calendar.get(Calendar.MILLISECOND), 3); }
From source file:TimeUtil.java
public static String monthStringFormat(long msecs) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date(msecs)); return monthStringFormat(cal.get(Calendar.MONTH)); }
From source file:com.project.framework.util.DateUtils.java
/** * ????/*from w ww. ja v a2 s.co m*/ * * @param start * * @param end * * @return start<end0start=endstart>end */ public static int compare(Date start, Date end) { Calendar c1 = Calendar.getInstance(); c1.setTime(start); Calendar c2 = Calendar.getInstance(); c2.setTime(end); int year1 = c1.get(Calendar.YEAR); int year2 = c2.get(Calendar.YEAR); if (year1 != year2) { return year1 - year2; } int month1 = c1.get(Calendar.MONTH); int month2 = c2.get(Calendar.MONTH); if (month1 != month2) { return month1 - month2; } int day1 = c1.get(Calendar.DAY_OF_MONTH); int day2 = c2.get(Calendar.DAY_OF_MONTH); return day1 - day2; }
From source file:Main.java
/** * Copy the year, month and day from a date to another * @param cOrigin Calendar origin where to get the data * @param cDestiny Calendar destiny where to set the data * @return Date with year month and day from dateOrigin and rest from dateDestiny *///from www.j a va 2s. c o m public static Calendar copyYearMonthDay(Calendar cOrigin, Calendar cDestiny) { //check null values if (cOrigin == null && cDestiny == null) { return Calendar.getInstance(); } else if (cOrigin == null) { return cDestiny; } else if (cDestiny == null) { return cOrigin; } //copy year, month and day cDestiny.set(Calendar.YEAR, cOrigin.get(Calendar.YEAR)); cDestiny.set(Calendar.MONTH, cOrigin.get(Calendar.MONTH)); cDestiny.set(Calendar.DAY_OF_MONTH, cOrigin.get(Calendar.DAY_OF_MONTH)); //return the time of destiny return cDestiny; }
From source file:com.jennifer.ui.util.TimeUtil.java
public static Date add(Date d, String type, int interval) { Calendar c = Calendar.getInstance(); c.setTime(d);/*from w ww . j a v a 2 s. com*/ if (Time.YEARS.equals(type)) { c.add(Calendar.YEAR, interval); } else if (Time.MONTHS.equals(type)) { c.add(Calendar.MONTH, interval); } else if (Time.DAYS.equals(type)) { c.add(Calendar.DATE, interval); } else if (Time.HOURS.equals(type)) { c.add(Calendar.HOUR_OF_DAY, interval); } else if (Time.MINUTES.equals(type)) { c.add(Calendar.MINUTE, interval); } else if (Time.SECONDS.equals(type)) { c.add(Calendar.SECOND, interval); } else if (Time.MILLISECONDS.equals(type)) { c.add(Calendar.MILLISECOND, interval); } else if (Time.WEEKS.equals(type)) { c.add(Calendar.DATE, interval * 7); } return c.getTime(); }
From source file:net.sf.sze.service.impl.common.SchulKalenderServiceImpl.java
/** * {@inheritDoc}/*from w w w . java2s. co m*/ */ @Override public int getSchuljahr(final Calendar currentDate) { if (currentDate.get(Calendar.MONTH) >= Calendar.AUGUST) { return currentDate.get(Calendar.YEAR) + 1; } else { return currentDate.get(Calendar.YEAR); } }
From source file:DateHelper.java
/** * Calculating age from a current date//ww w.ja v a 2 s. c o m * * @param current * @param birthdate * @return Age from the current (arg) date */ public static float getAge(final Date current, final Date birthdate) { if (birthdate == null) { return 0; } if (current == null) { return getAge(birthdate); } else { final Calendar calend = new GregorianCalendar(); calend.set(Calendar.HOUR_OF_DAY, 0); calend.set(Calendar.MINUTE, 0); calend.set(Calendar.SECOND, 0); calend.set(Calendar.MILLISECOND, 0); calend.setTimeInMillis(current.getTime() - birthdate.getTime()); float result = 0; result = calend.get(Calendar.YEAR) - 1970; result += (float) calend.get(Calendar.MONTH) / (float) 12; return result; } }