MyClass m = new MyClass(); Date dateToBeSet = new Date(); m.setBillDate(dateToBeSet); //The actual dateToBeSet is set to m dateToBeSet.setYear(...); //^^^^^^^^ Un-intentional modification to dateToBeSet, will also modify the m's billDate
/**根据生日获取年龄 * @param birthday * @return */ public static int getAge(Date birthday) { if (birthday == null) { return 0; } if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) { birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]); } return getAge(new int[]{birthday.getYear(), birthday.getMonth(), birthday.getDay()}); } /**根据生日获取年龄
/** * @param birthday * @return */ public static String getSmartBirthday(Date birthday) { if (birthday == null) { return ""; } if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) { birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]); } return getSmartBirthday(birthday.getTime(), false) + " " + (TimeUtil .getDateDetail(System.currentTimeMillis())[0] - birthday.getYear()) + "岁"; } /**获取智能生日
/**根据生日获取年龄 * @param birthday * @return */ public static int getAge(Date birthday) { if (birthday == null) { return 0; } if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) { birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]); } return getAge(new int[]{birthday.getYear(), birthday.getMonth(), birthday.getDay()}); } /**根据生日获取年龄
/** * @param birthday * @return */ public static String getSmartBirthday(Date birthday) { if (birthday == null) { return ""; } if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) { birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]); } return getSmartBirthday(birthday.getTime(), false) + " " + (TimeUtil .getDateDetail(System.currentTimeMillis())[0] - birthday.getYear()) + "岁"; } /**获取智能生日
/** * Sets the currently specified date. * * @param currentDate the currently specified date */ public void setCurrentMonth(Date currentDate) { this.currentMonth.setYear(currentDate.getYear()); this.currentMonth.setMonth(currentDate.getMonth()); }
@Override public void setYear(int year) { checkFrozen(); super.setYear(year); }
/** * Adds the given number of months to a date. * * @param date the date * @param months number of months */ @SuppressWarnings("deprecation") // GWT requires Date public static void addMonthsToDate(Date date, int months) { if (months != 0) { int month = date.getMonth(); int year = date.getYear(); int resultMonthCount = year * 12 + month + months; int resultYear = (int) Math.floor(resultMonthCount / 12.0); int resultMonth = resultMonthCount - resultYear * 12; date.setMonth(resultMonth); date.setYear(resultYear); } }
private void setDate(Date date) { if (getDatePicker().isYearAndMonthDropdownVisible()) { // setup months dropdown int month = date.getMonth(); monthSelect.setSelectedIndex(month); // setup years dropdown yearSelect.clear(); int year = date.getYear(); int startYear = year - getNoOfYearsToDisplayBefore(); int endYear = year + getNoOfYearsToDisplayAfter(); Date newDate = new Date(); for (int i = startYear; i <= endYear; i++) { newDate.setYear(i); yearSelect.addItem(getModel().getYearFormatter().format(newDate)); } yearSelect.setSelectedIndex(year - startYear); } else { grid.setText(0, monthColumn, getModel().formatCurrentMonthAndYear()); } }
public DateFormatSymbols() { threshold = new Date(); threshold.setYear(threshold.getYear()-80); this.twoDigitYearStart = threshold; }
@Test public void fromDate() { Date date = new Date(); date.setYear(0); date.setMonth(0); date.setDate(1); assertEquals(1900, new DateTime(date).getYear()); assertEquals(1, new DateTime(date).getMonth()); assertEquals(1, new DateTime(date).getDayOfMonth()); }
@Test public void fromDate() { Date date = new Date(); date.setYear(0); date.setMonth(0); date.setDate(1); assertEquals(1900, new DateTime(date).getYear()); assertEquals(1, new DateTime(date).getMonth()); assertEquals(1, new DateTime(date).getDayOfMonth()); }
@Test public void fromDate() { Date date = new Date(); date.setYear(0); date.setMonth(0); date.setDate(1); assertEquals(1900, new DateTime(date).getYear()); assertEquals(1, new DateTime(date).getMonth()); assertEquals(1, new DateTime(date).getDayOfMonth()); }
@Override public void setYear(int year) { checkFrozen(); super.setYear(year); }
/** * Sets the currently specified date. * * @param currentDate the currently specified date */ public void setCurrentMonth(Date currentDate) { this.currentMonth.setYear(currentDate.getYear()); this.currentMonth.setMonth(currentDate.getMonth()); }
public static String getMonthName(int month){ Locale locale = Locale.getDefault(); SimpleDateFormat sdf = new SimpleDateFormat("MMMM",locale); Date date = new Date(); date.setDate(1); date.setMonth(month); date.setYear(2012); return sdf.format(date); }
@SuppressWarnings("deprecation") public void setYear(int year) { Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_UTIL_DATE, this, "setYear", "(I)V", new Object[] {year}); super.setYear(year); Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_UTIL_DATE, this, CaptureLog.RETURN_TYPE_VOID); }