Countries and regions around the world have different local times because they are at different longitudes, resulting in distinct time zones. This topic describes time zones in Hologres.
Introduction to time zones
To avoid confusion, the world is officially divided into 24 time zones: 12 eastern and 12 western. The prime meridian, which passes through the former Royal Observatory in Greenwich, UK, defines the zero time zone. Eastern time zones are numbered 1 to 12 (+), and western time zones are numbered 1 to 12 (-). Each time zone spans 15 degrees of longitude, representing a one-hour difference. Internationally, two standards are used to express time zones: GMT and UTC.
-
GMT 0:00
Greenwich Mean Time (GMT) is based on observations from the Royal Observatory in Greenwich, UK. It was once used as the world standard time.
-
UTC +00:00
Coordinated Universal Time (UTC) is the current world standard time. Because the Earth's rotation gradually slows down—adding a fraction of a second each year—the organization that manages UTC periodically adds a leap second to keep atomic time (UTC) aligned with astronomical time, which reflects human perception.
-
UTC is not tied to any specific location and does not represent a local time. You must add a time zone offset to specify a local time. Therefore, GMT is not equivalent to UTC; rather, GMT equals
UTC+0. The relationship is expressed asGMT = UTC+0. Greenwich simply lies within the zero time zone. -
+08denotes the UTC+8 time zone, which is eight hours ahead of the zero time zone.
Hologres is compatible with the PostgreSQL protocol, which follows the POSIX timezone specification. In this specification, the sign of the timezone offset is reversed, which means a negative sign indicates an east timezone. Hologres stores all date and time values in Coordinated Universal Time (UTC). By default, all regions use the UTC-08 timezone (China Standard Time), which is eight hours ahead of UTC. Hologres also provides two data types for storing timestamps: TIMESTAMP for values without timezone information and TIMESTAMPTZ for values with timezone information.
For data that includes time zone information, use the TIMESTAMPTZ data type.
|
Name |
Description |
Precision |
Data Display Example |
|
TIMESTAMP |
The format is The stored data is the same as the written data. When you change the client's time zone, the stored value does not change. The client displays the raw data that was written, with no time zone offset. |
Microsecond |
2022-01-01 01:01:01.123456 |
|
TIMESTAMP WITH TIME ZONE (TIMESTAMPTZ) |
The format is Hologres stores TIMESTAMPTZ data as UTC values. When you insert a value into a TIMESTAMPTZ field, Hologres automatically converts the value from the client's time zone to UTC. When displaying query results, Hologres converts the UTC value back to the client's local time based on the client's TimeZone parameter. |
Millisecond |
2022-02-01 10:33:20.125+08 |
View the default time zone
-
View the current client's time zone.
show timezone;Note-
In HoloWeb, the result shows the instance's default time zone (PRC), which corresponds to UTC+8.
-
If you use other developer tools and the query result differs from the default time zone, the client's time zone configuration has been modified.
-
-
View the time zone for each region by querying a system table.
In PostgreSQL, the pg_timezone_names system table stores default time zone information for different regions. Run the following command to query this system table and view the time zone for each region.
select * from pg_timezone_names;The parameters of the system table are described below.
Parameter
Type
Description
name
text
The time zone name.
abbrev
text
The time zone abbreviation.
utc_offset
interval
The offset from UTC. A positive value (+) indicates east of Greenwich. A negative value (-) indicates west of Greenwich.
is_dst
boolean
True (t) if daylight saving time is currently in effect. Otherwise, false (f).
Change the client time zone
-
Hologres supports the following formats for specifying a time zone.
-
Full time zone name, such as America/New_York.
-
UTC time zone offset: For example, an offset of -08:00:00 or UTC-08 corresponds to the UTC+8 time zone. This is because the POSIX time zone specification reverses the sign for GMT and UTC offsets. Therefore, a negative sign (-) indicates a time zone east of UTC.
-
The following table lists common time zones in Hologres and their corresponding parameter values.
|
Region |
Time zone |
Full time zone name |
UTC offset |
|
UTC+08 |
|
UTC+08 |
|
Japan (Tokyo) |
UTC+09 |
Asia/Tokyo |
UTC+09 |
|
Indonesia (Jakarta) |
UTC+07 |
Asia/Jakarta |
UTC+07 |
|
Germany (Frankfurt) |
UTC+01 |
Europe/Berlin |
UTC+01 |
|
US (Virginia) |
UTC-05 |
|
UTC-05 |
|
US (Silicon Valley) |
UTC-08 |
|
UTC-08 |
-
Change the client time zone
By default, Hologres stores time in UTC. The default time zone for all regions is
UTC+08(China Standard Time). You can change the time zone displayed on the client by setting the time zone parameter with the following command.NoteChanging the time zone affects only how it is displayed on the client. It does not alter the actual time zone information in the underlying storage.
-
Session level
Use the SET command to configure a Grand Unified Configuration (GUC) parameter at the session level. Session-level parameters apply only to the current session and expire when the connection closes. Place the command before your SQL statement as follows.
--Change the time zone to Canada/Eastern. set timezone ='Canada/Eastern'; --Change to the fifth time zone west of UTC. set timezone ='05:30:00'; -
Database level
Use the
ALTER DATABASE <db_name> SET <value>;command to configure a GUC parameter at the database level.NoteAfter running this command:
-
The setting applies to the entire database. You must disconnect and reconnect for the change to take effect.
-
The setting does not apply to new databases. You must configure it manually for each new database.
The usage is as follows.
-- Change the database-level time zone to UTC-0. alter database <db_name> set timezone = 'UTC-0'; -- Change the database-level time zone to UTC+5. alter database <db_name> set timezone = 'UTC+05'; -
-
Time type mapping between different data sources and Hologres
The following table shows the data type mappings for time-related data between different data sources and Hologres. Follow the recommended mappings to avoid data inconsistencies or time zone drift.
|
Data Source |
Data Source Data Type |
Source Data Example |
Hologres Data Type |
Mapped Hologres Data Example |
Description |
|
MySQL |
DATETIME |
2001-07-14 02:14:19 |
TIMESTAMP |
2001-07-14 02:14:19 |
The DATETIME type in MySQL stores time without time zone information. The value range is When data is stored, it is saved in its original time format without any conversion. Therefore, map it to the TIMESTAMP type in Hologres. |
|
TIMESTAMP |
2019-02-23 05:21:16 |
TIMESTAMPTZ |
2019-02-23 05:21:16+08 |
The TIMESTAMP type in MySQL defaults to UTC time with a time zone. The value range is Before data is stored, the written time data is converted to UTC based on the database software's time zone setting, which defaults to the system time zone. Therefore, map it to the TIMESTAMPTZ type in Hologres. |
|
|
MaxCompute |
DATETIME |
2021-11-29 00:01:00 |
TIMESTAMPTZ |
2021-11-29 00:01:00.000+08 |
The DATETIME type in MaxCompute defaults to UTC time. The value range is |
|
TIMESTAMP |
2021-01-11 00:00:00.123456789 |
TIMESTAMPTZ |
2021-01-11 00:00:00.123+08 |
The TIMESTAMP type in MaxCompute defaults to UTC time. The value range is Note
Note: Hologres converts nanoseconds to milliseconds at the underlying layer, so you do not need to worry about precision issues. |
|
|
Flink |
TIMESTAMP |
2007-04-30 13:10:02.047 |
TIMESTAMPTZ |
2007-04-30 13:10:02.047+08 |
The TIMESTAMP type in Flink defaults to UTC time with millisecond precision. Therefore, map it to the TIMESTAMPTZ type in Hologres. |
|
DataHub |
TIMESTAMP |
2020-03-05 10:10:00.123456+08 |
TIMESTAMPTZ |
2020-03-05 10:10:00.123+08 |
The TIMESTAMP type in DataHub has microsecond precision and uses UTC time. The Hologres connector automatically converts the data's time zone to the zero time zone during the write process. Therefore, map it to the TIMESTAMPTZ type in Hologres. |
FAQ
-
When I synchronize data in real time from DataHub to Hologres, the time in Hologres is eight hours behind the actual time. The field type is TIMESTAMP in both DataHub and Hologres.
-
Cause: The Hologres connector automatically converts the data's time zone to the zero time zone during the write process. If the Hologres field is set to TIMESTAMP, it does not include time zone information. The data is written in the zero time zone, which is eight hours behind.
-
Solution: Re-create the table and change the field type in Hologres to TIMESTAMPTZ.
-
-
When I synchronize data in real time from DataHub to Hologres, the time displayed in Tableau differs by eight hours from the time in Hologres. The field type in Hologres is TIMESTAMPTZ.
-
Cause: This is a time zone display issue on the Tableau frontend.
-
Solution: HoloWeb uses UTC+08 as the default time zone. You can verify the data accuracy in HoloWeb. Then, when establishing a connection in Tableau, you can adjust the time zone in the Initial SQL field using the following command.
--Display time in the UTC+8 time zone. set timezone to 'Asia/Shanghai';
-
-
Why does
+08appear in the time display after I synchronize data from MySQL to Hologres?-
Cause:
+08indicates that the current client is displaying time in the UTC+8 time zone. It does not mean the stored data itself is in the UTC+8 time zone. -
Solution: Change the client's time zone to the desired time zone.
-
-
How do I set the time zone in Java Database Connectivity (JDBC)?
The time zone displayed in JDBC defaults to the Java Virtual Machine (JVM) time zone. To change the time zone display in JDBC, connect to JDBC and run the following SQL statement.
--Change to the UTC+7 time zone. set timezone = '+07';