List of utility methods to do Date Create
Date | add24HtoDate(Date date) add Hto Date Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.setTimeInMillis(date.getTime()); cal.add(Calendar.DATE, 1); return new Date(cal.getTimeInMillis()); |
Date | addTimeToDate(Date date, Date time) Adds specified time of day to a date. String dateAndTime = formatDateNoTime(date) + " " + formatTime(time); ParsePosition pos = new ParsePosition(0); Date result = dateFormatter1.parse(dateAndTime, pos); if ((result != null) && (pos.getIndex() < dateAndTime.length())) result = null; return result; |
Date | buildDate(int y, int m, int d) build Date Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m - 1);
cal.set(Calendar.DAY_OF_MONTH, d);
return cal.getTime();
|
Date | buildDate(String dateAsString) build Date try { return DATE_FORMATTER.parse(dateAsString); } catch (Exception e) { throw new RuntimeException("Failed to parse date - " + dateAsString, e); |
SimpleDateFormat | buildDateFormat(final String pattern) Get a SimpleDateFormat object by given pattern. SimpleDateFormat simpleDateFormat = simpleDateFormatCache.get(); if (simpleDateFormat == null) { simpleDateFormat = new SimpleDateFormat(); simpleDateFormatCache.set(simpleDateFormat); simpleDateFormat.applyPattern(pattern); return simpleDateFormat; |
Date | buildDatetime(Date datePart, Date hourMinutePart) build Datetime String str = formatDate(datePart) + " " + formatHourMinute(hourMinutePart) + ":00.000"; Date result = parseFullDatetime(str); return result; |
Date | buildDateTime(String curDate, String curTime, String meridiem) Build the date object according to the date and time value from the page. Date newDate = null; if (curDate != null && !"".equals(curDate.trim()) && curTime != null && !"".equals(curTime.trim())) { String dateToParse = curDate + " " + curTime + " " + meridiem; DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); try { newDate = format.parse(dateToParse); } catch (ParseException paex) { newDate = null; ... |
String | buildDateTimeUTC(Calendar cal) Builds a dateTime value in UTC from a Calendar value.
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); f.setTimeZone(TimeZone.getTimeZone("UTC")); return f.format(cal.getTime()); |
Date | castToDate(Object value) cast To Date if (value == null) { return null; if (value instanceof Calendar) { return ((Calendar) value).getTime(); if (value instanceof Date) { return (Date) value; ... |
Calendar | create(int year, int month, int date, TimeZone timeZone) create Calendar c = Calendar.getInstance(timeZone);
c.set(year, month - 1, date, 0, 0, 0);
c.set(Calendar.MILLISECOND, 0);
return c;
|