public boolean isSaturday(Date d) { return d.getDay() == 7; }
/** * 日期转换 * * @return 08.07 */ public static String convertDataToString(String dateString) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATA_FORMAT_PATTEN_YYYY_MM_DD, Locale.CHINA); Date date = null; try { date = simpleDateFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } if (date == null) return ""; return (String.valueOf(date.getMonth()).length() == 1 ? "0" + date.getMonth() : String.valueOf(date.getMonth())) + "." + (String.valueOf(date.getDay()).length() == 1 ? "0" + date.getDay() : String.valueOf(date.getDay())); }
/**根据生日获取年龄 * @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 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()}); } /**根据生日获取年龄
@SuppressWarnings("deprecation") public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { if (object == null) { serializer.out.writeNull(); return; } Date date = (Date) object; JSONObject json = new JSONObject(); json.put("date", date.getDate()); json.put("day", date.getDay()); json.put("hours", date.getHours()); json.put("minutes", date.getMinutes()); json.put("month", date.getMonth()); json.put("seconds", date.getSeconds()); json.put("time", date.getTime()); json.put("timezoneOffset", date.getTimezoneOffset()); json.put("year", date.getYear()); serializer.write(json); } }
int miladiMonth = MiladiDate.getMonth() + 1; int miladiDate = MiladiDate.getDate(); int WeekDay = MiladiDate.getDay();
Date today = new Date(); Date myDate = new Date(today.getYear(),today.getMonth()-1,today.getDay()); System.out.println("My Date is"+myDate); System.out.println("Today Date is"+today); if (today.compareTo(myDate)<0) System.out.println("Today Date is Lesser than my Date"); else if (today.compareTo(myDate)>0) System.out.println("Today Date is Greater than my date"); else System.out.println("Both Dates are equal");
/** * Gets the first day of the first week in the currently specified month. * * @return the first day */ public Date getCurrentFirstDayOfFirstWeek() { int wkDayOfMonth1st = currentMonth.getDay(); int start = CalendarUtil.getStartingDayOfWeek(); if (wkDayOfMonth1st == start) { // always return a copy to allow SimpleCalendarView to adjust first // display date return new Date(currentMonth.getTime()); } else { Date d = new Date(currentMonth.getTime()); int offset = wkDayOfMonth1st - start > 0 ? wkDayOfMonth1st - start : DAYS_IN_WEEK - (start - wkDayOfMonth1st); CalendarUtil.addDaysToDate(d, -offset); return d; } }
/** * Formats Day of week field according to pattern specified. * * @param buf where formatted string will be appended to * @param count number of time pattern char repeats; this controls how a field * should be formatted * @param date hold the date object to be formatted */ private void formatDayOfWeek(StringBuilder buf, int count, Date date) { @SuppressWarnings("deprecation") int value = date.getDay(); if (count == 5) { buf.append(dateTimeFormatInfo.weekdaysNarrow()[value]); } else if (count == 4) { buf.append(dateTimeFormatInfo.weekdaysFull()[value]); } else { buf.append(dateTimeFormatInfo.weekdaysShort()[value]); } }
/** * Formats Standalone weekday field according to pattern specified. * * @param buf where formatted string will be appended to * @param count number of time pattern char repeats; this controls how a field * should be formatted * @param date hold the date object to be formatted */ private void formatStandaloneDay(StringBuilder buf, int count, Date date) { @SuppressWarnings("deprecation") int value = date.getDay(); if (count == 5) { buf.append(dateTimeFormatInfo.weekdaysNarrowStandalone()[value]); } else if (count == 4) { buf.append(dateTimeFormatInfo.weekdaysFullStandalone()[value]); } else if (count == 3) { buf.append(dateTimeFormatInfo.weekdaysShortStandalone()[value]); } else { zeroPaddingNumber(buf, value, 1); } }
/** * Constructor. */ public CalendarModel() { currentMonth = new Date(); CalendarUtil.setToFirstDayOfMonth(currentMonth); // Finding day of week names Date date = new Date(); for (int i = 1; i <= DAYS_IN_WEEK; i++) { date.setDate(i); int dayOfWeek = date.getDay(); dayOfWeekNames[dayOfWeek] = getDayOfWeekFormatter().format(date); } // Finding day of month names date.setMonth(0); for (int i = 1; i < MAX_DAYS_IN_MONTH; ++i) { date.setDate(i); dayOfMonthNames[i] = getDayOfMonthFormatter().format(date); } // finding month names date.setDate(1); for (int i = 0; i < MONTHS_IN_YEAR; ++i) { date.setMonth(i); monthOfYearNames[i] = getMonthFormatter().format(date); } }
/** * Returns the day of the week * * @return the day of the week */ public int getDay() { return date.getDay(); }
/** * Returns the day of the week * * @return the day of the week */ public int getDayInWeek() { return date.getDay(); }
@Test public void retirePatientIdentifierType_shouldRetireAndSetReasonAndRetiredByAndDate() { PatientService ps = Context.getPatientService(); PatientIdentifierType pit = ps.getPatientIdentifierType(1); String reason = "moved away"; PatientIdentifierType result = ps.retirePatientIdentifierType(pit, reason); assertTrue(result.getRetired()); assertEquals(result.getRetireReason(), reason); assertEquals(result.getRetiredBy(), Context.getAuthenticatedUser()); Date today = new Date(); Date dateRetired = result.getDateRetired(); assertEquals(dateRetired.getDay(), today.getDay()); assertEquals(dateRetired.getMonth(), today.getMonth()); assertEquals(dateRetired.getYear(), today.getYear()); }
Date date1; //Your initial date Date date2; //Your initial second date //Remove hours, minutes, seconds and milliseconds by creating new "clean" Date objects Date compare1 = new Date(date1.getYear(), date1.getMonth(), date1.getDay()); Date compare2 = new Date(date2.getYear(), date2.getMonth(), date2.getDay()); if(compare1.compareTo(compare2) == 0){ }
@SuppressWarnings("deprecation") @Override public boolean isWorkingDay(Locale locale, Date date) { return date.getDay() != 0 && !isHoliday(locale, date); }
Date todayDate = new Date(); todayDate.getDay(); todayDate.getHours(); todayDate.getMinutes(); todayDate.getMonth(); todayDate.getTime();
@SuppressWarnings("deprecation") public static long getMinute(Date date){ GregorianCalendar calendar = new GregorianCalendar(1900+date.getYear(),date.getMonth(),date.getDay(),date.getHours(),date.getMinutes()); return calendar.getTimeInMillis(); }
@SuppressWarnings("deprecation") public int getDay() { Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_UTIL_DATE, this, "getDays", "()I", new Object[] {}); int ret = super.getDay(); Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_UTIL_DATE, this, ret); return ret; }