Configure a timezone

Updated at:

This topic describes how to use the SET command to configure the timezone for a MaxCompute project.

The timezone feature is supported for the following job types:

  • MapReduce provides a time zone feature.

  • Spark

    • For tasks submitted to a MaxCompute compute cluster, the project timezone is automatically retrieved.

    • For applications started in yarn-client mode, such as spark-shell, spark-sql, and pyspark, you must manually configure the driver's startup parameters. In the spark-defaults.conf file, add spark.driver.extraJavaOptions -Duser.timezone=America/Los_Angeles. Set the timezone value to the timezone you want to use.

  • PAI provides time zone support.

  • Graph supports time zones.

Configure a timezone

By default, the timezone for a MaxCompute project is China Standard Time (UTC+8). DATETIME, TIMESTAMP, and DATE fields and related built-in time functions are calculated based on this timezone. You can configure the timezone in one of two ways:

  • Session level: Run the SET odps.sql.timezone=<timezoneid>; statement. This statement must be submitted with the compute statement.

    --Set the timezone to Asia/Tokyo.
    SET odps.sql.timezone=Asia/Tokyo;
    --Query the current timezone.
    SELECT getdate();
    output:
    +------------+
    | _c0        |
    +------------+
    | 2018-10-30 23:49:50 |
    +------------+
  • Project level: Run the setproject odps.sql.timezone=<timezoneid>; statement. A project owner must run this command.

    Important

    If you set a project's timezone, related time calculations use the new timezone. This change affects data in existing jobs. Therefore, carefully evaluate whether this change is necessary. If it is, set the timezone only for new projects. Do not change the timezone for projects that already contain data.

Limits and notes

  • Built-in SQL date functions, user-defined functions (UDFs), user-defined types (UDTs), user-defined joins (UDJs), and SELECT TRANSFORM can retrieve the Project Timezone property to configure the timezone.

  • The supported timezone format is Asia/Shanghai, which accounts for daylight saving time changes. The GMT+9 format is not supported.

  • When the software development kit (SDK) timezone differs from the project timezone, you must set the timezone to GMT for operations that convert DATETIME types to STRING types.

  • After you configure the timezone, the display of dates for some time periods may differ when you run related SQL statements in DataWorks. For example, the date and time difference for the period from 1900 to 1928 is 5 minutes and 52 seconds. The date and time difference for periods before 1900 is 9 seconds.

  • To ensure the accuracy of DATETIME data across multiple timezones in MaxCompute, the MaxCompute service, Java SDK, and clients are updated. These updated versions have an -oversea suffix. After the update, the display of DATETIME data stored in MaxCompute from before 1928 may be affected.

  • For regions outside of China Standard Time (UTC+8), update your Java SDK or client versions. This ensures the accuracy and consistency of SQL calculation results and Tunnel data transfers for dates after 1900-01-01. For DATETIME data before 1900-01-01, a difference of 343 seconds may still exist between SQL calculation display results and Tunnel data transfers. For new SDK or client versions, DATETIME data uploaded before 1928-01-01 displays a date and time that is 352 seconds earlier.

  • If you continue to use an SDK or client without the -oversea suffix, differences exist between SQL calculation results and Tunnel data transfers. The difference is 9 seconds for data before 1900-01-01. The difference is 352 seconds for data from 1900-01-01 to 1928-01-01.

    Note

    Updating the Java SDK or client version to configure the timezone does not affect the timezone configuration in DataWorks. Therefore, a timezone difference exists. You must calculate and evaluate the impact on scheduled tasks in DataWorks. The DataWorks server timezone is GMT+9 in the Japan region and GMT+8 in the Singapore region.

  • For third-party clients that connect through Java Database Connectivity (JDBC), configure the timezone on the client to ensure it is consistent with the server-side timezone setting.