List of utility methods to do Timestamp
String | getTimeString(Timestamp timestamp) get Time String DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { String str = sdf.format(timestamp); return str; } catch (Exception e) { e.printStackTrace(); return null; ... |
Timestamp | getTodayTimestamp() get Today Timestamp Calendar cal = new GregorianCalendar(); cal.set(GregorianCalendar.HOUR, 0); cal.set(GregorianCalendar.HOUR_OF_DAY, 0); cal.set(GregorianCalendar.MINUTE, 0); cal.set(GregorianCalendar.SECOND, 0); cal.set(GregorianCalendar.MILLISECOND, 0); long todayInMillis = cal.getTime().getTime(); Timestamp ts = new Timestamp(todayInMillis); ... |
java.util.Date | getUtilDate(java.sql.Timestamp time) Convert SQL timestamp to Java Date if (time != null) return new java.util.Date(time.getTime()); else return null; |
Integer | getValue(Timestamp t) get Value Integer tempMinSum = 0;
tempMinSum += t.getHours() * 3600;
tempMinSum += t.getMinutes() * 60;
tempMinSum += t.getMinutes();
return tempMinSum;
|
ZonedDateTime | getZonedDateTime(final Timestamp timestamp) get Zoned Date Time return timestamp != null ? ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault()) : null;
|
boolean | hasTimeExpired(Timestamp referenceTime) has Time Expired long currentTime = getCurrentTime().getTime(); if (referenceTime != null && currentTime < referenceTime.getTime()) { return false; return true; |
boolean | inRange(Timestamp start, Timestamp end, boolean OnMonday, boolean OnTuesday, boolean OnWednesday, boolean OnThursday, boolean OnFriday, boolean OnSaturday, boolean OnSunday) Is start..end on one of the days ? if (OnSaturday && OnSunday && OnMonday && OnTuesday && OnWednesday && OnThursday && OnFriday) return false; GregorianCalendar calStart = new GregorianCalendar(); calStart.setTimeInMillis(start.getTime()); int dayStart = calStart.get(Calendar.DAY_OF_WEEK); GregorianCalendar calEnd = new GregorianCalendar(); calEnd.setTimeInMillis(end.getTime()); calEnd.add(Calendar.DAY_OF_YEAR, -1); ... |
java.sql.Timestamp | internalToTimestamp(long v) Converts the internal representation of a SQL TIMESTAMP (long) to the Java type used for UDF parameters ( java.sql.Timestamp ). return new java.sql.Timestamp(v); |
boolean | isAllDay(Timestamp start, Timestamp end) Is all day GregorianCalendar calStart = new GregorianCalendar(); calStart.setTimeInMillis(start.getTime()); GregorianCalendar calEnd = new GregorianCalendar(); calEnd.setTimeInMillis(end.getTime()); if (calStart.get(Calendar.HOUR_OF_DAY) == calEnd.get(Calendar.HOUR_OF_DAY) && calStart.get(Calendar.MINUTE) == calEnd.get(Calendar.MINUTE) && calStart.get(Calendar.SECOND) == calEnd.get(Calendar.SECOND) && calStart.get(Calendar.MILLISECOND) == calEnd.get(Calendar.MILLISECOND) ... |
boolean | isDifferentDay(final Timestamp ts1, final Timestamp ts2) is Different Day final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(ts1.getTime()); final int day1 = cal.get(Calendar.DAY_OF_MONTH), month1 = cal.get(Calendar.MONTH), year1 = cal.get(Calendar.YEAR); cal.setTimeInMillis(ts2.getTime()); final int day2 = cal.get(Calendar.DAY_OF_MONTH), month2 = cal.get(Calendar.MONTH), year2 = cal.get(Calendar.YEAR); return (day1 != day2 || month1 != month2 || year1 != year2); ... |