Refine search
/** * Constructs a MonthDay from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the MonthDay. * <p> * This factory method always creates a MonthDay with ISO chronology. * * @param date the Date to extract fields from * @return the created MonthDay, never null * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the monthOfYear or dayOfMonth is invalid for the ISO chronology */ @SuppressWarnings("deprecation") public static MonthDay fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new MonthDay(date.getMonth() + 1, date.getDate()); }
/** * Constructs a YearMonth from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the YearMonth. * <p> * This factory method always creates a YearMonth with ISO chronology. * * @param date the Date to extract fields from * @return the created YearMonth, never null * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the year or month is invalid for the ISO chronology */ @SuppressWarnings("deprecation") public static YearMonth fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new YearMonth(date.getYear() + 1900, date.getMonth() + 1); }
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");
/** * Determines if the specified timestamps denote time points within the same calendar month. * @param timestamp The timestamp * @param referenceTimestamp The timestamp to compare to. * @return {@code true} if the specified timestamps denote the same month, otherwise {@code false}. */ @SuppressWarnings("deprecation") public static boolean isSameCalendarMonth(long timestamp, long referenceTimestamp) { Date timestampDate = new Date(timestamp); Date referenceTimestampDate = new Date(referenceTimestamp); return timestampDate.getMonth() == referenceTimestampDate.getMonth() && isSameCalendarYear(timestamp, referenceTimestamp); }
/** * Constructs a YearMonthDay from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the YearMonthDay. * This is useful if you have been using the Date as a local date, * ignoring the zone. * <p> * This factory method always creates a YearMonthDay with ISO chronology. * * @param date the Date to extract fields from * @return the created YearMonthDay * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the date is invalid for the ISO chronology * @since 1.2 */ public static YearMonthDay fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new YearMonthDay( date.getYear() + 1900, date.getMonth() + 1, date.getDate() ); }
/** * Checks if the mob file is expired. * @param column The descriptor of the current column family. * @param current The current time. * @param fileDate The date string parsed from the mob file name. * @return True if the mob file is expired. */ public static boolean isMobFileExpired(ColumnFamilyDescriptor column, long current, String fileDate) { if (column.getMinVersions() > 0) { return false; } long timeToLive = column.getTimeToLive(); if (Integer.MAX_VALUE == timeToLive) { return false; } Date expireDate = new Date(current - timeToLive * 1000); expireDate = new Date(expireDate.getYear(), expireDate.getMonth(), expireDate.getDate()); try { Date date = parseDate(fileDate); if (date.getTime() < expireDate.getTime()) { return true; } } catch (ParseException e) { LOG.warn("Failed to parse the date " + fileDate, e); return false; } return false; }
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 static void main(String[] args) { for(int i=0;i<10; i++) { Date date = new Date(); Date updated = (Date)date.clone(); addMonths(updated, i); System.out.println(" original: " + date+ " adding " +i+ " months: " + updated); } } public static void addMonths(Date date, int numMonths){ date.setMonth((date.getMonth() - 1 + numMonths) % 12 + 1); }
/** * Constructs a YearMonthDay from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the YearMonthDay. * This is useful if you have been using the Date as a local date, * ignoring the zone. * <p> * This factory method always creates a YearMonthDay with ISO chronology. * * @param date the Date to extract fields from * @return the created YearMonthDay * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the date is invalid for the ISO chronology * @since 1.2 */ public static YearMonthDay fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new YearMonthDay( date.getYear() + 1900, date.getMonth() + 1, date.getDate() ); }
/** * Constructs a YearMonth from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the YearMonth. * <p> * This factory method always creates a YearMonth with ISO chronology. * * @param date the Date to extract fields from * @return the created YearMonth, never null * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the year or month is invalid for the ISO chronology */ @SuppressWarnings("deprecation") public static YearMonth fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new YearMonth(date.getYear() + 1900, date.getMonth() + 1); }
/** * Constructs a MonthDay from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the MonthDay. * <p> * This factory method always creates a MonthDay with ISO chronology. * * @param date the Date to extract fields from * @return the created MonthDay, never null * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the monthOfYear or dayOfMonth is invalid for the ISO chronology */ @SuppressWarnings("deprecation") public static MonthDay fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new MonthDay(date.getMonth() + 1, date.getDate()); }
/** * Instantiate an AutoML object and start it running. Progress can be tracked via its job(). * * @param buildSpec * @return */ public static AutoML startAutoML(AutoMLBuildSpec buildSpec) { Date startTime = new Date(); // this is the one and only startTime for this run synchronized (AutoML.class) { // protect against two runs whose startTime is the same second if (lastStartTime != null) { while (lastStartTime.getYear() == startTime.getYear() && lastStartTime.getMonth() == startTime.getMonth() && lastStartTime.getDate() == startTime.getDate() && lastStartTime.getHours() == startTime.getHours() && lastStartTime.getMinutes() == startTime.getMinutes() && lastStartTime.getSeconds() == startTime.getSeconds()) startTime = new Date(); } lastStartTime = startTime; } String keyString = buildSpec.build_control.project_name; AutoML aml = AutoML.makeAutoML(Key.<AutoML>make(keyString), startTime, buildSpec); DKV.put(aml); startAutoML(aml); return aml; }
@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()); }
@SuppressWarnings("deprecation") public static Date getSameOrClosestDateInNextMonth(Date date) { Date desiredDate = new Date(date.getTime()); CalendarUtil.addMonthsToDate(desiredDate, 1); if (desiredDate.getMonth() > date.getMonth() + 1) { // skipped one month, e.g. 30 January -> 2nd (or 1st for leap-year) March, because February does not have 30th // set the date to last day of previous month CalendarUtil.setToFirstDayOfMonth(desiredDate); CalendarUtil.addDaysToDate(desiredDate, -1); } return desiredDate; }
/** * Constructs a YearMonthDay from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the YearMonthDay. * This is useful if you have been using the Date as a local date, * ignoring the zone. * <p> * This factory method always creates a YearMonthDay with ISO chronology. * * @param date the Date to extract fields from * @return the created YearMonthDay * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the date is invalid for the ISO chronology * @since 1.2 */ public static YearMonthDay fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new YearMonthDay( date.getYear() + 1900, date.getMonth() + 1, date.getDate() ); }
/** * Constructs a YearMonth from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the YearMonth. * <p> * This factory method always creates a YearMonth with ISO chronology. * * @param date the Date to extract fields from * @return the created YearMonth, never null * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the year or month is invalid for the ISO chronology */ @SuppressWarnings("deprecation") public static YearMonth fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new YearMonth(date.getYear() + 1900, date.getMonth() + 1); }
/** * Constructs a MonthDay from a <code>java.util.Date</code> * using exactly the same field values avoiding any time zone effects. * <p> * Each field is queried from the Date and assigned to the MonthDay. * <p> * This factory method always creates a MonthDay with ISO chronology. * * @param date the Date to extract fields from * @return the created MonthDay, never null * @throws IllegalArgumentException if the calendar is null * @throws IllegalArgumentException if the monthOfYear or dayOfMonth is invalid for the ISO chronology */ @SuppressWarnings("deprecation") public static MonthDay fromDateFields(Date date) { if (date == null) { throw new IllegalArgumentException("The date must not be null"); } return new MonthDay(date.getMonth() + 1, date.getDate()); }
private static long getMonthsDifference(long fromMs, long toMs) { if (fromMs <= DATETIME_MILLIS_NEVER || toMs <= fromMs ) { return 0; } // TODO: Migrate to java.util.time, see http://stackoverflow.com/questions/1086396/java-date-month-difference Date date1 = new Date(fromMs); Date date2 = new Date(toMs); return (date2.getYear() - date1.getYear()) * 12L + (date2.getMonth() - date1.getMonth()); }