public static Date firstDayOfNextMonth() { MutableDateTime mdt = new MutableDateTime(); mdt.addMonths(1); mdt.setDayOfMonth(1); mdt.setMillisOfDay(0); // if you want to make sure you're at midnight return mdt.toDate(); }
@Override public Date parse(final String source, final ParsePosition pos) { final MutableDateTime mutableDateTime = new MutableDateTime(); this.dateTimeFormatter.parseInto(mutableDateTime, source, pos.getIndex()); return mutableDateTime.toDate(); } }
public static Date cloneDateIfNotNullAndStripOffMillisOfSecond(final Date date) { if (date == null) { return null; } final MutableDateTime mutableDateTime = new MutableDateTime(date); mutableDateTime.setMillisOfSecond(0); return mutableDateTime.toDate(); }
String dateStr = "2009218"; MutableDateTime mdt = new MutableDateTime(); mdt.setYear(Integer.parseInt(dateStr.subString(0,3))); mdt.setDayOfYear(Integer.parseInt(dateStr.subString(4))); Date parsedDate = mdt.toDate();
date = dt.toDate();
private void updateDateTime() { final Date date = getDate(); if (date != null) { final MutableDateTime dateTime = new MutableDateTime(date); try { final TimeZone zone = getClientTimeZone(); if (zone != null) { dateTime.setZone(DateTimeZone.forTimeZone(zone)); } setHourAndMinutes(dateTime); // the date will be in the server's timezone setDate(dateTime.toDate()); setModelObject(dateTime.toDate()); } catch (final RuntimeException e) { error(e.getMessage()); invalid(); } } }
@Override public void onClick(AjaxRequestTarget target) { ((FormComponent<Date>) YuiDateTimeField.this.get("date")).clearInput(); MutableDateTime date = new MutableDateTime(new Date()); boolean use12HourFormat = use12HourFormat(); int hours = date.getHourOfDay() % (use12HourFormat ? 12 : 24); setHours(hours); setMinutes(date.getMinuteOfHour()); setDate(date.toDate()); if (target != null) { target.addComponent(YuiDateTimeField.this); } }
@Override public void onClick(AjaxRequestTarget target) { ((FormComponent<Date>) YuiDateTimeField.this.get("date")).clearInput(); MutableDateTime date = new MutableDateTime(new Date()); boolean use12HourFormat = use12HourFormat(); int hours = date.getHourOfDay() % (use12HourFormat ? 12 : 24); setHours(hours); setMinutes(date.getMinuteOfHour()); setDate(date.toDate()); if (target != null) { target.addComponent(YuiDateTimeField.this); } }
private void updateDateTime(Object datetime, Integer hours, Integer minutes, AjaxRequestTarget target) { MutableDateTime date = new MutableDateTime(datetime); try { TimeZone zone = getClientTimeZone(); if (zone != null) { date.setZone(DateTimeZone.forTimeZone(zone)); } if (hours != null) { date.set(DateTimeFieldType.hourOfDay(), hours.intValue() % 24); date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0); } // the date will be in the server's timezone setModelObject(date.toDate()); if (target != null) { target.add(this); } } catch (RuntimeException e) { error(e.getMessage()); invalid(); } }
private void updateDateTime(Object datetime, Integer hours, Integer minutes, AjaxRequestTarget target) { MutableDateTime date = new MutableDateTime(datetime); try { TimeZone zone = getClientTimeZone(); if (zone != null) { date.setZone(DateTimeZone.forTimeZone(zone)); } if (hours != null) { date.set(DateTimeFieldType.hourOfDay(), hours.intValue() % 24); date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0); } // the date will be in the server's timezone setModelObject(date.toDate()); if (target != null) { target.addComponent(this); } } catch (RuntimeException e) { error(e.getMessage()); invalid(); } }
private void updateDateTime(Date date, Integer hours, Integer minutes) { if(date!=null) { MutableDateTime datetime = new MutableDateTime(date); try { TimeZone zone = getClientTimeZone(); if (zone != null) { datetime.setZone(DateTimeZone.forTimeZone(zone)); } if (hours != null) { datetime.set(DateTimeFieldType.hourOfDay(), hours % 24); datetime.setMinuteOfHour(minutes != null ? minutes : 0); } // the date will be in the server's timezone setDate(datetime.toDate()); //setModelObject(datetime.toDate()); } catch (RuntimeException e) { error(e.getMessage()); invalid(); } } }
private void updateDateTime(Date date, Integer hours, Integer minutes) { if(date!=null) { MutableDateTime datetime = new MutableDateTime(date); try { TimeZone zone = getClientTimeZone(); if (zone != null) { datetime.setZone(DateTimeZone.forTimeZone(zone)); } if (hours != null) { datetime.set(DateTimeFieldType.hourOfDay(), hours % 24); datetime.setMinuteOfHour(minutes != null ? minutes : 0); } // the date will be in the server's timezone setDate(datetime.toDate()); //setModelObject(datetime.toDate()); } catch (RuntimeException e) { error(e.getMessage()); invalid(); } } }