Skip to content

Date, Time, Time Zone

Mirro Mutth edited this page Feb 27, 2024 · 7 revisions

Related Configuration Options

These options will affect how the driver uses time zones, and their impact should be the same as mysql-connector-j.

See also https://dev.mysql.com/blog-archive/support-for-date-time-types-in-connector-j-8-0/

All supported Java types

Instant values

They will be affected by preserveInstants and connectionTimeZone.

  • java.time.ZonedDateTime
  • java.time.OffsetDateTime
  • java.time.Instant

Non-instant values

They are not affected by time zones.

  • java.time.LocalDateTime
  • java.time.LocalDate
  • java.time.LocalTime
  • java.time.OffsetTime
  • java.time.Duration: during TIME field can be a value between '-838:59:59.000000' to '838:59:59.000000'
  • java.time.Year

Changelog

  1. Since 0.8.2, option serverZoneId is available
    • Used to specify the time zone of the connection. If not set, driver will query server time zone on initialization
    • Driver receive "zoned" date time and converts its time zone to local: ZonedDateTime, Instant, OffsetDateTime and OffsetTime
    • Driver send "zoned" date times with connection time zone
    • All "local" date times (e.g. LocalDateTime) time zone will not be converted
  2. Since 1.0.4, change DATETIME/TIMESTAMP default mapping to ZonedDateTime
  3. Since 1.1.2, considering various factors and the impact of feedback on version 1.0.4, we finally made adjustments to make behavior as same as possible with JDBC
    • Add preserveInstants, forceConnectionTimeZoneToSession, and connectionTimeZone
    • Default connectionTimeZone to "LOCAL", which means driver will use JVM local time zone by default
    • OffsetTime will no longer be affected by time zone
    • Default DATETIME to LocalDateTime, TIMESTAMP to ZonedDateTime
      • In JDBC, TIMESTAMP should be java.sql.Timestamp by default, but we avoid using the old date time type