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
/** * 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 va2s. 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: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);/*from w ww. j a va 2 s . c o 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.ykun.commons.utils.commons.DateUtils.java
/** * // w w w.ja v a 2 s . c om * * @param date * @param yearAmount * @return Date */ public static Date addYear(Date date, int yearAmount) { return addInteger(date, Calendar.YEAR, yearAmount); }
From source file:DateHelper.java
/** * Calculating age from a current date// www. ja va 2s . 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; } }
From source file:egovframework.com.utl.wed.filter.DirectoryPathManager.java
/** * 2012/12/22///from ww w .j a v a2s. co m * @param dateType * @return * @throws InvalidArgumentException */ public static String getDirectoryPathByDateType(DIR_DATE_TYPE policy) { Calendar calendar = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(calendar.get(Calendar.YEAR)).append(File.separator); if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH)), 2, '0')) .append(File.separator); } if (policy.ordinal() <= DIR_DATE_TYPE.DATE_POLICY_YYYY_MM_DD.ordinal()) { sb.append(StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)), 2, '0')) .append(File.separator); } return sb.toString(); }
From source file:cz.cvut.kbss.wpa.service.test.PlayerServiceTest.java
@BeforeClass public static void setUp() { b = Calendar.getInstance();//from w ww.j a v a 2s .c om b.set(Calendar.YEAR, 1986); b.set(Calendar.MONTH, Calendar.APRIL); b.set(Calendar.DAY_OF_MONTH, 28); b.set(Calendar.HOUR, 0); b.set(Calendar.MINUTE, 0); b.set(Calendar.SECOND, 0); }
From source file:Main.java
/** * Get current year//from ww w . jav a 2 s .c om * * @return */ public static int getCurrentYear() { return Calendar.getInstance().get(Calendar.YEAR); }
From source file:is.idega.idegaweb.egov.gumbo.licenses.SetDraganotveidiValidPeriod.java
public void execute(ExecutionContext executionContext) throws Exception { final Interval period; final Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR, 0);//from www.j a v a 2 s. c o m now.set(Calendar.MINUTE, 0); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); final Calendar mayStart = Calendar.getInstance(); mayStart.set(now.get(Calendar.YEAR), Calendar.MAY, 1, 0, 0, 0); final Calendar augEnd = Calendar.getInstance(); augEnd.set(now.get(Calendar.YEAR), Calendar.AUGUST, 31, 0, 0, 0); if (now.after(mayStart) && now.before(augEnd)) { period = new Interval(now.getTime(), augEnd.getTime()); } else { period = findNearestPeriod(now); } executionContext.setVariable("date_validityFrom", period.getFrom()); executionContext.setVariable("date_validityTo", period.getTo()); }
From source file:Main.java
/** * Determines what year a transaction belongs to. * //from w ww . ja va 2s .co m * If the given <code>day</code> of the given <code>month</code> for the current year * is in the future the transaction is probably from last year. * * @param month The month, where January is 1. * @param day The day of the month, starting from 1. * @return An ISO 8601 formatted date. */ public static String getTransactionDate(int month, int day) { month--; // Java-months start at 0 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); int currentYear = cal.get(Calendar.YEAR); cal.set(currentYear, month, day, 0, 0); if (cal.getTime().after(Calendar.getInstance().getTime())) { //If the transaction is in the future the year is probably of by +1. cal.add(Calendar.YEAR, -1); } return sdf.format(cal.getTime()); }
From source file:net.sf.sze.service.impl.common.SchulKalenderServiceImpl.java
/** * {@inheritDoc}//ww w . ja v a 2 s .c o 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); } }