Java Utililty Methods SQL Date Get

List of utility methods to do SQL Date Get

Description

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

Method

longgetDateAsLong(ResultSet rset, Enum field)
get Date As Long
return getDateAsLong(rset, field.name());
longgetDateAsLong(Timestamp date)
Gets the date as long.
return date == null ? -1 : date.getTime();
DategetDateBefore(Date date, Integer before)
get Date Before
if (before == 0) {
    return new Date(date.getTime());
Date d = new Date(date.getTime());
for (int i = 0; i < before; i++) {
    d.setTime(d.getTime() - 86400000);
return d;
...
DategetDateBeforTwelveMonth()
get Date Befor Twelve Month
String date = "";
Calendar cla = Calendar.getInstance();
cla.setTime(getCurrentDate());
int year = cla.get(Calendar.YEAR) - 1;
int month = cla.get(Calendar.MONTH) + 1;
if (month > 9) {
    date = String.valueOf(year) + DATE_DIVISION + String.valueOf(month) + DATE_DIVISION + "01";
} else {
...
StringgetDateByNum(String dateNum)
get Date By Num
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = sdf.format(new Date((long) (Double.parseDouble(dateNum) * 1000)));
return date;
DategetDateByYearAndMonth(int year, int month)
get Date By Year And Month
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
Date date = new Date(calendar.getTimeInMillis());
return date;
MapgetDateDiscrepancy(String startDate, String endDate)
get Date Discrepancy
try {
    Map<String, Long> result = new HashMap<String, Long>();
    Date start = dateFormat.parse(startDate);
    Date end = dateFormat.parse(endDate);
    long allsecond = (end.getTime() - start.getTime()) / 1000;
    long day = allsecond / (24 * 3600);
    long hour = allsecond % (24 * 3600) / 3600;
    long minute = allsecond % 3600 / 60;
...
DategetDateEnd(Date date)
get Date End
String dateStr = parseDate2(date, "yyyy-MM-dd");
dateStr = dateStr + " 23:59:59";
return parseDateTime(dateStr);
DategetDateForStr(String str)
get Date For Str
java.sql.Date sqlDate = java.sql.Date.valueOf(str);
return sqlDate;
DategetDateFromISODateString(String isoDate)
get Date From ISO Date String
String year = getCurrentYear();
return getDateFromRTGSDateString(year + isoDate);