List of utility methods to do Timestamp Convert To
short | timestampToDayNumber(long timestamp) timestamp To Day Number long result = timestamp / (1000 * 60 * 60 * 24); if (result < 0 || result > Short.MAX_VALUE) { throw new IllegalArgumentException("Wrong date input '" + result + "'"); return (short) result; |
long | timestampToInternal(java.sql.Timestamp ts) Converts the Java type used for UDF parameters of SQL TIMESTAMP type ( java.sql.Timestamp ) to internal representation (long). return ts.getTime();
|
long | timestampToLong(Timestamp ts) Convert a timestamp to seconds. return (ts.getTime() / 1000) - (ts.getTimezoneOffset() * 60);
|
long | timestampToMicros(Timestamp timestamp) Converts a Timestamp to microseconds since the Unix epoch (1970-01-01T00:00:00Z). long millis = timestamp.getTime() * 1000L; long micros = (timestamp.getNanos() % 1000000L) / 1000L; if (micros >= 0) { return millis + micros; } else { return millis + 1000000L + micros; |
int[] | timestampToParts(long time) Returns the given time as int array that has exactly 6 items:
int s = (int) Math.floor(time / 1000); int ms = (int) (time - s * 1000); int w = (int) Math.floor(s / 604800); s -= w * 604800; int d = (int) Math.floor(s / 86400); s -= d * 86400; int h = (int) Math.floor(s / 3600); s -= h * 3600; ... |
String | timestampToPrettyString(long ts) Format ts from "0m00" to "59m59", then "1h00" to "xxxxh59" long s = (ts /= 1000) % 60; long m = (ts /= 60) % 60; long h = ts / 60; return (h > 0 ? (h + "h") : "") + ((m < 10 && h > 0) ? "0" : "") + m + (h == 0 ? ("m" + ((s < 10) ? "0" : "") + s) : ""); |
String | timestampToSearchString(final Timestamp timestamp) timestamp To Search String if (timestamp == null) { return ""; return timestamp.toString(); |
String | timestampToString(long time) Formats the given time into string like "7w 1d 2h 34m 56s". int[] t = timestampToParts(time); StringBuilder result = new StringBuilder(); if (t[5] > 0) result.append(t[5]).append("w "); if (t[4] > 0) result.append(t[4]).append("d "); if (t[3] > 0) result.append(t[3]).append("h "); ... |
long | timestampToTicks(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds) Converts a field by field timestamp into millisecond ticks. boolean isLeapYear = isLeapYear(year); long dayComponent = (long) (day - 1) * MILLIS_PER_DAY; long monthComponent = millisToStartOfMonth(month, isLeapYear); long yearComponent = millisToYearStart(year); long hoursComponent = (long) hours * MILLIS_PER_HOUR; long minutesComponent = (long) minutes * MILLIS_PER_MINUTE; long secondsComponent = (long) seconds * MILLIS_PER_SECOND; return dayComponent + monthComponent + yearComponent + hoursComponent + minutesComponent + secondsComponent ... |
Timestamp | to_timestamp(String date) ttimestamp return new Timestamp(to_date(date).getTime()); |