Class TimestampUtil
- java.lang.Object
-
- com.snowflake.connectors.util.sql.TimestampUtil
-
public class TimestampUtil extends Object
Utility class which provides mapping methods betweenTimestamp
andInstant
.The mapping methods should be used in order to properly save or fetch a UTC timestamp value from a TIMESTAMP_NTZ column.
The reason for using the methods is that Snowflake treats Timestamp as a date in your local time zone, and when the conversion is not handled properly - the information about the time zone can be lost, which leads to incorrect values saved in database or fetched from database.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Instant
toInstant(Timestamp timestamp)
Method for converting given Timestamp to Instant.static Timestamp
toTimestamp(Instant instant)
Method for converting given Instant to Timestamp.
-
-
-
Method Detail
-
toInstant
public static Instant toInstant(Timestamp timestamp)
Method for converting given Timestamp to Instant. This method should be used in order to keep given date in UTC format when it is needed to convert a Timestamp fetched from database to Instant. It should be used instead of Timestamp#toInstant, because Snowflake treats Timestamp object as a date in your local time zone and when you use Timestamp#toInstant() - the information about the time zone is being lost.- Parameters:
timestamp
- timestamp object in your local time zone- Returns:
- instant object in UTC time zone
-
toTimestamp
public static Timestamp toTimestamp(Instant instant)
Method for converting given Instant to Timestamp. The method converts a UTC Instant to a Timestamp in your local time zone, so that when this value is saved to a database to a TIMESTAMP_NTZ column, the value will be in UTC format.- Parameters:
instant
- instant object in UTC format- Returns:
- timestamp object in your local time zone
-
-