public class SqlDateTimeUtils extends Object
Modifier and Type | Field and Description |
---|---|
static TimeZone |
UTC_ZONE
The UTC time zone.
|
Constructor and Description |
---|
SqlDateTimeUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
convertTz(String dateStr,
String tzFrom,
String tzTo) |
static String |
convertTz(String dateStr,
String format,
String tzFrom,
String tzTo)
Convert datetime string from a time zone to another time zone.
|
static String |
dateAdd(long ts,
int days) |
static String |
dateAdd(long ts,
int days,
TimeZone tz)
Do addition on timestamp.
|
static String |
dateAdd(String dateStr,
int days) |
static String |
dateAdd(String dateStr,
int days,
TimeZone tz)
Do addition on date string.
|
static int |
dateDiff(long t1,
long t2) |
static int |
dateDiff(long t1,
long t2,
TimeZone tz)
NOTE: (1).
|
static int |
dateDiff(long t1,
String t2Str) |
static int |
dateDiff(long t1,
String t2Str,
TimeZone tz) |
static int |
dateDiff(String t1Str,
long t2) |
static int |
dateDiff(String t1Str,
long t2,
TimeZone tz) |
static int |
dateDiff(String t1Str,
String t2Str) |
static int |
dateDiff(String t1Str,
String t2Str,
TimeZone tz) |
static String |
dateFormat(long ts,
String format) |
static String |
dateFormat(long ts,
String format,
TimeZone tz)
Format a timestamp as specific.
|
static String |
dateFormat(String dateStr,
String toFormat) |
static String |
dateFormat(String dateStr,
String fromFormat,
String toFormat) |
static String |
dateFormat(String dateStr,
String fromFormat,
String toFormat,
TimeZone tz)
Format a string datetime as specific.
|
static String |
dateFormat(String dateStr,
String toFormat,
TimeZone tz) |
static String |
dateFormat(TimestampData ts,
String format) |
static String |
dateFormat(TimestampData ts,
String format,
TimeZone zone) |
static String |
dateFormat(TimestampData ts,
String format,
java.time.ZoneId zoneId)
Format a timestamp as specific.
|
static String |
dateFormatTz(long ts,
String tzStr) |
static String |
dateFormatTz(long ts,
String format,
String tzStr) |
static Integer |
dateStringToUnixDate(String s) |
static String |
dateSub(long ts,
int days) |
static String |
dateSub(long ts,
int days,
TimeZone tz)
Do subtraction on date string.
|
static String |
dateSub(String dateStr,
int days) |
static String |
dateSub(String dateStr,
int days,
TimeZone tz)
Do subtraction on date string.
|
static int |
dateToInternal(Date date)
Converts the Java type used for UDF parameters of SQL DATE type (
Date ) to
internal representation (int). |
static long |
dateToTimestampWithLocalZone(int date,
TimeZone tz) |
static long |
extractFromTimestamp(org.apache.calcite.avatica.util.TimeUnitRange range,
TimestampData ts,
TimeZone tz) |
static int |
extractYearMonth(org.apache.calcite.avatica.util.TimeUnitRange range,
int v) |
static long |
fromTimestamp(long ts) |
static String |
fromUnixtime(DecimalData unixtime) |
static String |
fromUnixtime(DecimalData unixtime,
TimeZone tz) |
static String |
fromUnixtime(double unixtime) |
static String |
fromUnixtime(double unixtime,
TimeZone tz) |
static String |
fromUnixtime(long unixtime) |
static String |
fromUnixtime(long unixtime,
String format) |
static String |
fromUnixtime(long unixtime,
String format,
TimeZone tz)
Convert unix timestamp (seconds since '1970-01-01 00:00:00' UTC) to datetime string in the
given format.
|
static String |
fromUnixtime(long unixtime,
TimeZone tz)
Convert unix timestamp (seconds since '1970-01-01 00:00:00' UTC) to datetime string in the
"yyyy-MM-dd HH:mm:ss" format.
|
static Date |
internalToDate(int v)
Converts the internal representation of a SQL DATE (int) to the Java type used for UDF
parameters (
Date ). |
static Time |
internalToTime(int v)
Converts the internal representation of a SQL TIME (int) to the Java type used for UDF
parameters (
Time ). |
static Timestamp |
internalToTimestamp(long v)
Converts the internal representation of a SQL TIMESTAMP (long) to the Java type used for UDF
parameters (
Timestamp ). |
static long |
localDateTimeToUnixTimestamp(java.time.LocalDateTime dateTime) |
static int |
localDateToUnixDate(java.time.LocalDate date) |
static int |
localTimeToUnixDate(java.time.LocalTime time) |
static int |
strToDate(String dateStr,
String fromFormat)
Returns the epoch days since 1970-01-01.
|
static long |
timestampCeil(org.apache.calcite.avatica.util.TimeUnitRange range,
long ts) |
static long |
timestampCeil(org.apache.calcite.avatica.util.TimeUnitRange range,
long ts,
TimeZone tz)
Keep the algorithm consistent with Calcite DateTimeUtils.julianDateFloor, but here we take
time zone into account.
|
static long |
timestampFloor(org.apache.calcite.avatica.util.TimeUnitRange range,
long ts) |
static long |
timestampFloor(org.apache.calcite.avatica.util.TimeUnitRange range,
long ts,
TimeZone tz) |
static long |
timestampToInternal(Timestamp ts)
Converts the Java type used for UDF parameters of SQL TIMESTAMP type (
Timestamp ) to internal representation (long). |
static String |
timestampToString(long ts,
int precision) |
static String |
timestampToString(long ts,
int precision,
TimeZone tz)
Convert a timestamp to string.
|
static String |
timestampToString(TimestampData ts,
int precision) |
static String |
timestampToString(TimestampData ts,
TimeZone tz,
int precision) |
static TimestampData |
timestampToTimestampWithLocalZone(TimestampData ts,
TimeZone tz) |
static int |
timestampWithLocalZoneToDate(long ts,
TimeZone tz) |
static int |
timestampWithLocalZoneToTime(long ts,
TimeZone tz) |
static TimestampData |
timestampWithLocalZoneToTimestamp(TimestampData ts,
TimeZone tz) |
static Integer |
timeStringToUnixDate(String v) |
static Integer |
timeStringToUnixDate(String v,
int start) |
static int |
timeToInternal(Time time)
Converts the Java type used for UDF parameters of SQL TIME type (
Time ) to
internal representation (int). |
static long |
timeToTimestampWithLocalZone(int time,
TimeZone tz) |
static int |
toDate(int v) |
static long |
toTimestamp(DecimalData v) |
static long |
toTimestamp(double v) |
static long |
toTimestamp(long v) |
static Long |
toTimestamp(String dateStr) |
static Long |
toTimestamp(String dateStr,
String format) |
static Long |
toTimestamp(String dateStr,
String format,
TimeZone tz)
Parse date time string to timestamp based on the given time zone and format.
|
static Long |
toTimestamp(String dateStr,
TimeZone tz)
Parse date time string to timestamp based on the given time zone and "yyyy-MM-dd HH:mm:ss"
format.
|
static TimestampData |
toTimestampData(String dateStr) |
static TimestampData |
toTimestampData(String dateStr,
String format) |
static Long |
toTimestampTz(String dateStr,
String tzStr) |
static Long |
toTimestampTz(String dateStr,
String format,
String tzStr)
Parse date time string to timestamp based on the given time zone string and format.
|
static TimestampData |
truncate(TimestampData ts,
int precision) |
static long |
unixDateCeil(org.apache.calcite.avatica.util.TimeUnitRange range,
long date) |
static java.time.LocalDate |
unixDateToLocalDate(int date) |
static long |
unixTimeExtract(org.apache.calcite.avatica.util.TimeUnitRange range,
int ts) |
static long |
unixTimestamp()
Returns a Unix timestamp in seconds since '1970-01-01 00:00:00' UTC as an unsigned integer.
|
static long |
unixTimestamp(long ts)
Returns the value of the timestamp to seconds since '1970-01-01 00:00:00' UTC.
|
static long |
unixTimestamp(String dateStr) |
static long |
unixTimestamp(String dateStr,
String format) |
static long |
unixTimestamp(String dateStr,
String format,
TimeZone tz)
Returns the value of the argument as an unsigned integer in seconds since '1970-01-01
00:00:00' UTC.
|
static long |
unixTimestamp(String dateStr,
TimeZone tz)
Returns the value of the argument as an unsigned integer in seconds since '1970-01-01
00:00:00' UTC.
|
static java.time.LocalDateTime |
unixTimestampToLocalDateTime(long timestamp) |
static java.time.LocalTime |
unixTimeToLocalTime(int time) |
static String |
unixTimeToString(int time)
Helper for CAST({time} AS VARCHAR(n)).
|
public static final TimeZone UTC_ZONE
public static Date internalToDate(int v)
Date
).public static Time internalToTime(int v)
Time
).public static Timestamp internalToTimestamp(long v)
Timestamp
).public static int dateToInternal(Date date)
Date
) to
internal representation (int).
Converse of internalToDate(int)
.
public static int timeToInternal(Time time)
Time
) to
internal representation (int).
Converse of internalToTime(int)
.
public static long timestampToInternal(Timestamp ts)
Timestamp
) to internal representation (long).
Converse of internalToTimestamp(long)
.
public static int toDate(int v)
public static long toTimestamp(long v)
public static long toTimestamp(double v)
public static long toTimestamp(DecimalData v)
public static TimestampData toTimestampData(String dateStr)
public static TimestampData toTimestampData(String dateStr, String format)
public static Long toTimestamp(String dateStr, TimeZone tz)
dateStr
- the date time stringtz
- the time zonepublic static Long toTimestamp(String dateStr, String format, TimeZone tz)
dateStr
- the date time stringformat
- date time string formattz
- the time zonepublic static Long toTimestampTz(String dateStr, String format, String tzStr)
dateStr
- the date time stringformat
- the date time string formattzStr
- the time zone id stringpublic static int strToDate(String dateStr, String fromFormat)
public static String dateFormat(TimestampData ts, String format, java.time.ZoneId zoneId)
ts
- the TimestampData
to format.format
- the string formatter.zoneId
- the ZoneId.public static String dateFormat(TimestampData ts, String format)
public static String dateFormat(TimestampData ts, String format, TimeZone zone)
public static String dateFormat(long ts, String format, TimeZone tz)
ts
- the timestamp to format.format
- the string formatter.tz
- the time zonepublic static String dateFormat(String dateStr, String fromFormat, String toFormat, TimeZone tz)
dateStr
- the string datetime.fromFormat
- the original date format.toFormat
- the target date format.tz
- the time zone.public static String convertTz(String dateStr, String format, String tzFrom, String tzTo)
dateStr
- the date time stringformat
- the date time formattzFrom
- the original time zonetzTo
- the target time zonepublic static String timestampToString(long ts, int precision)
public static String timestampToString(long ts, int precision, TimeZone tz)
ts
- the timestamp to convert.precision
- the milli second precision to preservetz
- the time zonepublic static String unixTimeToString(int time)
public static int extractYearMonth(org.apache.calcite.avatica.util.TimeUnitRange range, int v)
public static long unixTimeExtract(org.apache.calcite.avatica.util.TimeUnitRange range, int ts)
public static long extractFromTimestamp(org.apache.calcite.avatica.util.TimeUnitRange range, TimestampData ts, TimeZone tz)
public static long timestampFloor(org.apache.calcite.avatica.util.TimeUnitRange range, long ts)
public static long timestampFloor(org.apache.calcite.avatica.util.TimeUnitRange range, long ts, TimeZone tz)
public static long timestampCeil(org.apache.calcite.avatica.util.TimeUnitRange range, long ts)
public static long timestampCeil(org.apache.calcite.avatica.util.TimeUnitRange range, long ts, TimeZone tz)
public static int dateDiff(long t1, long t2, TimeZone tz)
public static int dateDiff(long t1, long t2)
public static int dateDiff(String t1Str, long t2)
public static int dateDiff(long t1, String t2Str)
public static String dateSub(String dateStr, int days, TimeZone tz)
dateStr
- formatted date string.days
- days count you want to subtract.tz
- time zone of the date time stringpublic static String dateSub(long ts, int days, TimeZone tz)
ts
- the timestamp.days
- days count you want to subtract.tz
- time zone of the date time stringpublic static String dateSub(long ts, int days)
public static String dateAdd(String dateStr, int days, TimeZone tz)
dateStr
- formatted date string.days
- days count you want to add.public static String dateAdd(long ts, int days, TimeZone tz)
ts
- the timestamp.days
- days count you want to add.public static String dateAdd(long ts, int days)
public static long fromTimestamp(long ts)
public static String fromUnixtime(long unixtime, TimeZone tz)
public static String fromUnixtime(long unixtime, String format, TimeZone tz)
public static String fromUnixtime(DecimalData unixtime, TimeZone tz)
public static String fromUnixtime(long unixtime)
public static String fromUnixtime(double unixtime)
public static String fromUnixtime(DecimalData unixtime)
public static long unixTimestamp()
public static long unixTimestamp(String dateStr, TimeZone tz)
public static long unixTimestamp(String dateStr, String format, TimeZone tz)
public static long unixTimestamp(String dateStr)
public static long unixTimestamp(long ts)
public static java.time.LocalDate unixDateToLocalDate(int date)
public static int localDateToUnixDate(java.time.LocalDate date)
public static java.time.LocalTime unixTimeToLocalTime(int time)
public static int localTimeToUnixDate(java.time.LocalTime time)
public static java.time.LocalDateTime unixTimestampToLocalDateTime(long timestamp)
public static long localDateTimeToUnixTimestamp(java.time.LocalDateTime dateTime)
public static TimestampData timestampToTimestampWithLocalZone(TimestampData ts, TimeZone tz)
public static TimestampData timestampWithLocalZoneToTimestamp(TimestampData ts, TimeZone tz)
public static int timestampWithLocalZoneToDate(long ts, TimeZone tz)
public static int timestampWithLocalZoneToTime(long ts, TimeZone tz)
public static long dateToTimestampWithLocalZone(int date, TimeZone tz)
public static long timeToTimestampWithLocalZone(int time, TimeZone tz)
public static String timestampToString(TimestampData ts, int precision)
public static String timestampToString(TimestampData ts, TimeZone tz, int precision)
public static long unixDateCeil(org.apache.calcite.avatica.util.TimeUnitRange range, long date)
public static TimestampData truncate(TimestampData ts, int precision)
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.