Java Utililty Methods Date Start

List of utility methods to do Date Start

Description

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

Method

DategetStart(Date date)
Returns the given date with the time set to the start of the day.
return clearTime(date);
DategetStartDate(Date date)
get Start Date
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
DategetStartDate(Date date)
get Start Date
return getFirstOfMonthCalendar(date).getTime();
DategetStartDate(Date date)

Description:Get Monday of the week the day specified by parameter belongs to

Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int day = calendar.get(Calendar.DAY_OF_WEEK);
int offset = offsets[day - Calendar.SUNDAY];
calendar.add(Calendar.DAY_OF_YEAR, offset);
return calendar.getTime();
StringgetStartDate(String date)
get Start Date
String startDate;
int year = getYear(date);
int month = getMonth(date);
int day = getDate(date);
int curDayOfWeek = getDayOfWeek(year, month, day);
int startTmp = 1 - curDayOfWeek;
Calendar tmpCalendar = Calendar.getInstance();
tmpCalendar.set(year, month - 1, day);
...
DategetStartDateOfCurrentSemester()
get Start Date Of Current Semester
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
if (month >= 9 && month <= 2) {
    cal.set(year, Calendar.OCTOBER, 1, 0, 0, 0);
    return cal.getTime();
} else {
    cal.set(year, Calendar.APRIL, 1, 0, 0, 0);
...
DategetStartDateOfCurrMonth()
get Start Date Of Curr Month
Calendar now = Calendar.getInstance();
now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), 1);
return now.getTime();
GregorianCalendargetStartDay(Date date)
get Start Day
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
for (int field = 0; field < 5; field++)
    cal.set(ORDERED_DATE_FIELD[field], 0);
return cal;
DategetStartDayOfNextMonth(Date date)
get Start Day Of Next Month
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.MONTH, 1);
c.set(Calendar.DAY_OF_MONTH, 1);
date = c.getTime();
return date;
DategetStartOfDate(final Date date)
Get start of date.
if (date == null)
    return null;
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
...