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

DatecreateDateObject(Integer year, Integer month, Integer dayOfMonth, Integer hourOfDay, Integer minute, Integer second, Integer milissecond)
Create a Date object based on default Calendar instance.
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
if (hourOfDay != null) {
    c.set(Calendar.HOUR_OF_DAY, hourOfDay);
if (minute != null) {
...
DatecreateDates(int yy, int mm, int dd, int hh, int min, int ss)
create Dates
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.YEAR, yy);
c1.set(Calendar.MONTH, mm);
c1.set(Calendar.DAY_OF_MONTH, dd);
c1.set(Calendar.HOUR_OF_DAY, hh);
c1.set(Calendar.MINUTE, min);
c1.set(Calendar.SECOND, ss);
return c1.getTime();
...
StringcreateDateString(long startDate, long endDate)
create Date String
GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault());
StringBuffer dateLine = new StringBuffer(50);
Formatter formatter = new Formatter(dateLine, Locale.ENGLISH);
cal.setTimeInMillis(startDate);
dateLine.append("From ");
formatter.format("%1$tH:%1$tM (GMT) %1$tb %1$te,%1$tY", cal);
cal.setTimeInMillis(endDate);
dateLine.append(" to ");
...
DatecreateDateTime(Date date, Date time)
combine a date (yy/mm/dd) and a time (hh:mm:ss) into a combined timestamp-date containing both date and time.
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(time);
cal1.set(Calendar.HOUR_OF_DAY, cal2.get(Calendar.HOUR_OF_DAY));
cal1.set(Calendar.MINUTE, cal2.get(Calendar.MINUTE));
cal1.set(Calendar.SECOND, cal2.get(Calendar.SECOND));
cal1.set(Calendar.MILLISECOND, cal2.get(Calendar.MILLISECOND));
...
DatecreateDateTime(int year, int month, int day, int hour, int minute, int second, String timezone)
create Date Time
TimeZone zone = null;
if (timezone != null && !timezone.isEmpty()) {
    zone = TimeZone.getTimeZone(timezone);
if (zone == null) {
    zone = TimeZone.getDefault();
Calendar calendar = Calendar.getInstance(zone);
...
DatecreateFutureDate()
create Future Date
GregorianCalendar futureDate = new GregorianCalendar(); 
futureDate.add(Calendar.MONTH, 2);
return futureDate.getTime();
LongcreateFutureDate(int min)
create Future Date
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, min);
return cal.getTimeInMillis();
DatecreateInitialDateQuery(final Date date)
Convert Date to same Date with first minute of day.
final Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
DatecreateTime(Date date)
create Time
Calendar time = new GregorianCalendar();
time.setTime(date);
time.set(1970, 0, 1);
return time.getTime();
Stringdate()
date
return String.format(DATE_FORMAT, getDate());