Java Utililty Methods Date Create

List of utility methods to do Date Create

Description

The list of methods to do Date Create are organized into topic(s).

Method

Dateadd24HtoDate(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());
DateaddTimeToDate(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;
DatebuildDate(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();
DatebuildDate(String dateAsString)
build Date
try {
    return DATE_FORMATTER.parse(dateAsString);
} catch (Exception e) {
    throw new RuntimeException("Failed to parse date - " + dateAsString, e);
SimpleDateFormatbuildDateFormat(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;
DatebuildDatetime(Date datePart, Date hourMinutePart)
build Datetime
String str = formatDate(datePart) + " " + formatHourMinute(hourMinutePart) + ":00.000";
Date result = parseFullDatetime(str);
return result;
DatebuildDateTime(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;
...
StringbuildDateTimeUTC(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());
DatecastToDate(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;
...
Calendarcreate(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;