Java Utililty Methods Day End

List of utility methods to do Day End

Description

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

Method

intgetNumYears(Date dStart, Date dEnd)
Gets the number of years between two date objects
GregorianCalendar now = new GregorianCalendar();
now.setTime(dEnd);
int curYear = now.get(Calendar.YEAR);
int curMonth = now.get(Calendar.MONTH) + 1;
int curDay = now.get(Calendar.DAY_OF_MONTH);
GregorianCalendar birthDate = new GregorianCalendar();
birthDate.setTime(dStart);
int birthYear = birthDate.get(Calendar.YEAR);
...
DategetSCDEndDate()
Returns the SCD end date: 2999-01-01 {Category} TimestampUtil {talendTypes} Date {example} getSCDEndDate().
if (scdEndDate == null) {
    scdEndDate = getIntAsDate(29990101);
return scdEndDate;
DategetSecondSemesterEndDate(Integer year)
get Second Semester End Date
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH + 1, 7);
calendar.set(Calendar.DAY_OF_MONTH, 1);
return calendar.getTime();
DategetSendTime(Date sendDate, Date start, Date end)
get Send Time
Calendar calendar = Calendar.getInstance();
if (sendDate != null) {
    calendar.setTime(sendDate);
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(start);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(end);
...
Date[]getStartAndEndDate(Date d)
return starting and ending dates within a day
Calendar cal = Calendar.getInstance();
cal.setTime(d);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date startDate = cal.getTime();
cal.set(Calendar.HOUR_OF_DAY, 23);
...
DategetStartOrEndTime(Date date, int flag)
parameter Date type data and 0 return 2016-08-04 00:00:00 parameter Date type data and 1 2016-08-04 12:59:59
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
long millisecond = hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000;
cal.setTimeInMillis(cal.getTimeInMillis() - millisecond);
if (flag == 0) {
...
intgetSubSeconds(Date minuendDate, Date subDate)
get Sub Seconds
Calendar minuend = Calendar.getInstance();
minuend.setTime(minuendDate);
Calendar sub = Calendar.getInstance();
sub.setTime(subDate);
return minuend.get(Calendar.SECOND) - sub.get(Calendar.SECOND);
longgetTimeBeetweenDates(Date d1, Date d2, int timeType)
get Time Beetween Dates
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(d1);
cal2.setTime(d2);
long diff = d2.getTime() - d1.getTime();
switch (timeType) {
case Calendar.SECOND:
    return (long) diff / 1000;
...
StringgetTimeInterval(Date startDate, Date endDate)
get Time Interval
long intervalSeconds = (endDate.getTime() - startDate.getTime()) / 1000L;
long hours = intervalSeconds / 3600L;
long minutes = (intervalSeconds % 3600L) / 60L;
long seconds = (intervalSeconds % 3600L) % 60L;
long days = hours / 24L;
if (days > 1) {
    return String.valueOf(days) + " days";
} else if (hours > 0) {
...
longgetTotalDays(Date startDate, Date endDate)
Provides the total difference in days between the two dates with accuracy taking for example time zones into consideration.
long millisecsPerDay = 86400000;
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
Calendar endCalender = Calendar.getInstance();
endCalender.setTime(endDate);
double endL = endCalender.getTimeInMillis()
        + endCalender.getTimeZone().getOffset(endCalender.getTimeInMillis());
double startL = startCalendar.getTimeInMillis()
...