All Products
Search
Document Center

Hologres:Time zone

Last Updated:Jul 17, 2024

Countries and regions around the world are classified into different time zones based on their longitudes and local time. This topic describes the system parameters that are related to time zones in Hologres.

Background information

To measure time in different regions, the world is divided into 24 time zones. 12 of them are in the Eastern Hemisphere, and the other 12 are in the Western Hemisphere. All time zones are defined based on their offsets from Greenwich Mean Time (GMT), which is the time of the Royal Observatory in Greenwich, Britain. The time zones in the Eastern Hemisphere are represented by offsets with plus signs (+), and the time zones in the Western Hemisphere are represented by offsets with minus signs (-). Each time zone covers 15 degrees of longitude. The time in a time zone differs by 1 hour from that in the neighboring time zones. The following two time standards are universally used as the basis of the time in a specific time zone:

  • GMT 0:00

    GMT is the time observed at the Royal Observatory in Greenwich, Britain. GMT was previously the time standard used all over the world.

  • UTC +00:00

    Coordinated Universal Time (UTC) is the primary time standard worldwide. Over time, the rotation of the Earth slows down. Therefore, each year is a few tenths of a second longer than the previous year. To prevent the observed time from deviating significantly from International Atomic Time (TAI), the International Earth Rotation and Reference Systems Service (IERS) adds a leap second to UTC time every several years. UTC has replaced GMT as the universal time standard.

Note
  • Different from GMT, UTC is not the time in a specific region. If you use UTC to represent the time in a time zone, you must add an integer with a plus sign (+) or a minus sign (-) to indicate the time zone. For example, you can refer to GMT by using UTC+0, which means no offset from UTC.

  • UTC+08 indicates the eighth time zone in the Eastern Hemisphere. In this time zone, the time is 8 hours ahead of that in the 0 time zone.

Hologres is compatible with PostgreSQL. PostgreSQL follows the POSIX time zone specifications. You must switch the offset symbols so that the minus sign (-) becomes the plus sign (+) and the plus sign (+) becomes the minus sign (-). A negative sign indicates eastern time zones, and a positive sign indicates western time zones. In Hologres, all date and time values use UTC to specify time zones. If no time zone is specified, the default time zone UTC-08 is used for all Alibaba Cloud regions. UTC-8 is the eighth time zone in the Eastern Hemisphere. The time in UTC-08 is 8 hours ahead of the time in UTC+0 or GMT. Hologres supports two timestamp data types, TIMESTAMP and TIMESTAMPTZ. Time zones are not specified in TIMESTAMP but are specified in TIMESTAMPTZ.

Note

We recommend that you use the TIMESTAMPTZ data type for data with time zones.

Data type

Description

Precision

Example

TIMESTAMP

Stores timestamp values in the Date + Time format, without specifying time zones.

This data type ensures that the stored timestamp values do not change based on the time zone specified for a client. The timestamp values stored on the client are the same as those written to the client and do not include time zone information.

Microseconds

2022-01-01 01:01:01.123456

TIMESTAMPTZ, which stands for TIMESTAMP WITH TIME ZONE

Stores timestamp values in the Date + Time format and specifies the time zone as a suffix to the value.

Hologres uses UTC to specify time zones. When you write values to columns of the TIMESTAMPTZ type in Hologres, Hologres automatically converts the time in the client time zone to the UTC+0 time zone. When you query timestamp values on the client, Hologres converts the time values in UTC+0 back to the client time zone based on the TimeZone parameter.

Millisecond

2022-02-01 10:33:20.125+08

Query the default time zone on a client

You can execute the following statement to query the default time zone on a client.

Note
  • If you execute the statement in HoloWeb, the default return value is PRC, which indicates UTC-08.

  • If you use another development tool and the query result is not the default time zone, the time zone setting was modified.

show timezone;

Modify the time zone setting on a client

  • Use the relevant system table

    The PostgreSQL system table named pg_timezone_names stores the information about default time zones of different countries and regions. You can execute the following statement to query the time zones of different countries and regions in the system table:

    select * from pg_timezone_names;

    The following table describes fields in the system table.

    Field

    Data type

    Description

    name

    text

    The name of the time zone.

    abbrev

    text

    The abbreviation of the time zone.

    utc_offset

    interval

    The UTC offset of the time zone. A positive offset indicates a time zone in the Western Hemisphere. A negative offset indicates a time zone in the Eastern Hemisphere.

    is_dst

    boolean

    Indicates whether daylight saving time (DST) is applied. If yes, the value of this parameter is true. Otherwise, the value of this parameter is false.

    The following table describes common time zones in Hologres.

    Region

    Time zone

    Full time zone name

    Offset from UTC+0

    • All regions in China

    • Singapore

    • Malaysia (Kuala Lumpur)

    Eighth time zone in the Eastern Hemisphere

    • PRC

    • Asia/Shanghai

    • Asia/Singapore

    • Asia/Kuala_Lumpur

    UTC-08

    Japan (Tokyo)

    Ninth time zone in the Eastern Hemisphere

    Asia/Tokyo

    UTC-09

    Indonesia (Jakarta)

    Seventh time zone in the Eastern Hemisphere

    Asia/Jakarta

    UTC-07

    Germany (Frankfurt)

    First time zone in the Eastern Hemisphere

    Europe/Berlin

    UTC-01

    US (Virginia)

    Fifth time zone in the Western Hemisphere

    • US/Eastern

    • America/New_York

    UTC+05

    US (Silicon Valley)

    Eighth time zone in the Western Hemisphere

    • US/Pacific

    • America/Los_Angeles

    UTC+08

  • Modify the time zone setting on a client

    By default, all time zones in Hologres are stored as UTC offsets. The default time zone of all Alibaba Cloud regions is UTC-08. You can modify the time zone setting on a client by using the TimeZone parameter. You can execute the following statements to modify the time zone setting on the client.

    Note
    • After you set the TimeZone parameter, only the time zone displayed on the client is changed, and the time zones of the stored data remain unchanged.

    • The default time zone displayed in HoloWeb is UTC-08.

    • Modify the time zone setting at the session level

      You can run the SET command to configure the Grand Unified Configuration (GUC) parameter at the session level. If you set the parameter at the session level, the setting takes effect only in the current session. After the session is closed, the setting becomes invalid. We recommend that you run the SET command before the SQL statement. Examples:

      -- Change the time zone to Canada/Eastern.
      set timezone ='Canada/Eastern';
      
      -- Change the time zone to the fifth time zone in the Eastern Hemisphere.
      set timezone ='05:00:00';           
    • Modify the time zone setting for a database

      You can execute the alter database <db_name> set <value>; statement to configure the GUC parameter for a database.

      Note

      Take note of the following items when you execute the statement:

      • To make the modification take effect for a database, disconnect the database from and then reconnect the database to the client.

      • The modification does not automatically apply to a new database. You must manually configure the GUC parameter for the new database.

      Examples:

      -- Change the time zone of a database to UTC+0.
      alter database <db_name> set timezone = 'UTC-0';
      
      -- Change the time zone of a database to the fifth time zone in the Western Hemisphere.
      alter database <db_name> set timezone = 'UTC+05';

Mappings of time-related data types between Hologres and other data sources

The following table describes the mappings of time-related data types between Hologres and other data sources. If a data type is not mapped based on the mappings, data or time zone inconsistency occurs.

Data source

Data type in a data source

Source data example

Data type in Hologres

Mapped example in Hologres

Description

MySQL

DATETIME

2001-07-14 02:14:19

TIMESTAMP

2001-07-14 02:14:19

Data of the DATETIME type in MySQL contains no time zone value. This type of data can be considered as strings. Valid values range from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

MySQL stores data of the DATETIME type in its original format. This type of data is mapped to data of the TIMESTAMP type in Hologres.

TIMESTAMP

2019-02-23 05:21:16

TIMESTAMPTZ

2019-02-23 05:21:16+08

By default, data of the TIMESTAMP type in MySQL follows the UTC format and contains a time zone value. Valid values range from '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

MySQL converts data of the TIMESTAMP type from the time zone configured for the database to UTC for storage. In MySQL, the default time zone value is that of the client. This data type is mapped to TIMESTAMPTZ in Hologres.

MaxCompute

DATETIME

2021-11-29 00:01:00

TIMESTAMPTZ

2021-11-29 00:01:00.000+08

By default, data of the DATETIME type in MaxCompute follows the UTC format and is accurate to milliseconds. Valid values range from '0000-1-1' to '9999-12-31'. This data type is mapped to TIMESTAMPTZ in Hologres.

TIMESTAMP

2021-01-11 00:00:00.123456789

TIMESTAMPTZ

2021-01-11 00:00:00.123+08

By default, data of the TIMESTAMP type in MaxCompute follows the UTC format and is accurate to nanoseconds. Valid values range from '0000-01-01 00:00:00.000000000' to '9999-12-31 23.59:59.999999999'. This data type is mapped to TIMESTAMPTZ in Hologres.

Note

The underlying layer of Hologres automatically converts nanoseconds into milliseconds. Therefore, you do not need to pay attention to the data precision in Hologres.

Flink

TIMESTAMP

2007-04-30 13:10:02.047

TIMESTAMPTZ

2007-04-30 13:10:02.047+08

By default, data of the TIMESTAMP type in Flink follows the UTC format and is accurate to milliseconds. This data type is mapped to TIMESTAMPTZ in Hologres.

DataHub

TIMESTAMP

2020-03-05 10:10:00.123456+08

TIMESTAMPTZ

2020-03-05 10:10:00.123+08

Data of the TIMESTAMP type in DataHub follows the UTC format and is accurate to microseconds. When you use a Hologres connector to write data of the TIMESTAMP type to Hologres, Hologres automatically converts the time zone value in the data into UTC+0. This data type is mapped to TIMESTAMPTZ in Hologres.

FAQ

  • When I synchronize data of the TIMESTAMP type from DataHub to Hologres in real time, the data type remains unchanged, but the time values written to Hologres are 8 hours earlier than the original time values. Why?

    • Possible cause: The Hologres connector automatically converts the time zone value in the original data into UTC+0 when you write data. If you use the TIMESTAMP data type in Hologres, the time values written to Hologres are considered to be in UTC+0 because data of the TIMESTAMP type contains no time zone value. The UTC+0 time zone is 8 hours earlier than the default time zone in Hologres.

    • Solution: Create a table in Hologres and change the mapped data type from TIMESTAMP to TIMESTAMPTZ.

  • When I synchronize data from DataHub to Hologres in real time, the data type is converted to TIMESTAMPTZ in Hologres. However, when I use Tableau to view the synchronized data, the displayed data has an 8-hour offset from the data stored in Hologres. Why?

    • Possible cause: The time zone displayed on the data page of Tableau is improper.

    • Solution: The default time zone in HoloWeb is UTC+08. Go to HoloWeb to check whether the displayed time zone is suitable for your business data. You can modify the time zone setting when you connect Tableau to Hologres by using the Initial SQL feature. Sample statement:

      -- Change the time zone displayed in Tableau to UTC+08.
      set timezone to 'Asia/Shanghai';
  • Why does the time data displayed in Hologres contain the value +08 after I synchronize the data from MySQL to Hologres?

    • Possible cause: The value +08 indicates the time zone on the current client, rather than the time zone of the synchronized data.

    • Solution: Modify the time zone setting on the client based on your business requirements.

  • How do I modify the time zone setting in Java Database Connectivity (JDBC)?

    By default, the time zone displayed in JDBC is the same as that in Java Virtual Machine (JVM). If you want to modify the time zone setting in JDBC, use JDBC to connect to Hologres and execute the following statement:

    -- Change the time zone to UTC+07.
    set timezone = '+07';