Java Utililty Methods Day of

List of utility methods to do Day of

Description

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

Method

longcalcDay(String date1, String date2, String format)
calc Day
SimpleDateFormat sdf = new SimpleDateFormat(format);
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse(date1));
long time1 = cal.getTimeInMillis();
cal.setTime(sdf.parse(date2));
long time2 = cal.getTimeInMillis();
return (time1 - time2) / (1000 * 3600 * 24);
StringcalcSunday(String queryDate)
calc Sunday
String result = null;
if (queryDate != null) {
    GregorianCalendar gc = new GregorianCalendar();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    try {
        gc.setTime(df.parse(queryDate));
        gc.add(5, -1);
        for (; gc.get(7) != 7; gc.add(5, 1))
...
intCountCmpHolidays(Date stdate, Date enddate, String[] CmpHoliDays)
Count Cmp Holidays
int NonWorkingDays = 0;
Calendar c1 = Calendar.getInstance();
DateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
try {
    c1.setTime(stdate);
    while ((stdate.compareTo(enddate)) < 0) {
        if (Arrays.binarySearch(CmpHoliDays, sdf1.format(c1.getTime())) >= 0) {
            NonWorkingDays += 1;
...
longcountDay(String begin, String end)
count Day
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date beginDate, endDate;
long day = 0;
try {
    beginDate = format.parse(begin);
    endDate = format.parse(end);
    day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
} catch (ParseException e) {
...
DateendOfTheDay(Date date)
end Of The Day
Calendar c = new GregorianCalendar();
c.setTime(date);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
StringformatDate(String day)
format Date
try {
    return yyyyMM.format(formatYearMonth(day));
} catch (Exception ex) {
    ex.printStackTrace();
return null;
StringformatDay(final Date time)
Formats the given time using the following pattern: 'MMM d, yyyy'.
final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DAY);
dateTimeFormat.setTimeZone(TimeZone.getDefault());
return time != null ? dateTimeFormat.format(time) : "";
java.util.DateformatDayTime(String day)
format Day Time
try {
    return yyyyMMdd.parse(day);
} catch (ParseException ex) {
    ex.printStackTrace();
    return new java.util.Date();
StringformatShortNameOfDay(final Date date)
format Short Name Of Day
final DateFormat df = new SimpleDateFormat("EE", Locale.getDefault());
df.setTimeZone(TimeZone.getDefault());
return df.format(date);
Stringget1DayBeforDate()
get Day Befor Date
Calendar now = Calendar.getInstance();
now.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH) - 1);
return getDate(now.getTime(), "yyyy-MM-dd");