Time Overview

This page describes how time and time zone detection works on Android. This includes how Android automatically detects time and time zones, configuration options for device manufacturers, and testing information.

Overview of time and time zones

To determine a user's local time for display in locations such as the status bar, Android keeps track of two related but independent states:

  • The current UTC time
  • The current time zone

The current UTC time and current time zone are device-wide states, meaning that they are shared by all users of a device.

The current UTC time isn't a fixed value. It updates automatically to reflect the passage of time. Besides the normal passage of time, the current UTC time of a device is adjusted if it's found to be incorrect, for example, after a device loses power.

The current time zone determines the adjustment to be made to convert the current UTC time into a local time. For example, during summer in Los Angeles, the device subtracts 7 hours from the current UTC time, and in winter it subtracts 8 hours.

To support these local time calculations, all Android devices have a database of all global time zone rules. For more information on time zone rules, see Time Zone Rules.

When a user travels to a new location that uses a different time zone, the current UTC time doesn't need to be adjusted but the user typically wants to see the local time rather than the time in their previous location. Changing the current time zone ensures that the correct offset is applied to the current UTC time to display the correct local time for the new location.

AOSP allows users to independently control whether the time and time zone are set automatically for them through the following mechanisms.

  • Automatic time detection: Ensures that the device has the correct current UTC time.
  • Automatic time zone detection: Ensures that the device has the correct current time zone.

Automatic time detection

This section provides an overview of the time_detector service that manages automatic time detection, user controls, configuration options, and testing details.

The time_detector service

The time_detector service, present on devices running Android 10 or higher, manages automatic time detection. It adjusts the device's current UTC time as needed when automatic time detection is enabled.

The time_detector service is always in one of two states: uncertain or certain. The service's certain or uncertain state is determined by time suggestions that it receives from various sources.

When the time_detector service is certain, meaning that it has received a suggestion with UTC time information, it overrides the current UTC time if the time suggestion is different from the current UTC time.

When time_detector is uncertain, it doesn't override the current time. The uncertain state usually means the time_detector service hasn't received time suggestions. The time_detector service also becomes uncertain if suggestions it has received are considered too old to be used. The age of suggestions is considered because adjustments using old UTC time suggestions rely on the elapsed realtime clock on the device, which is assumed to be inaccurate over long periods.

To establish the current UTC time automatically, a device has various sources it can use. These are called origins in this document. The time_detector service treats sequences of suggestions as distinct based on their origin.

The time_detector service is stateful, which means that it keeps a record of the most recent suggestion made by each origin. New suggestions are made to time_detector if an origin has more recent UTC time information available. The time_detector service re-evaluates new and existing suggestions and updates the device state when suggestions are received.

Although UTC time is agreed upon internationally, there are various reasons why establishing UTC time isn't always straightforward for an Android device:

  • Origins might only be available at certain times or under certain circumstances. For example, if the origin requires network connectivity, it might only be available while the device is connected to the internet.
  • The origins might be inaccurate or imprecise, or have errors. For example, if a telephony cell tower isn't tracking UTC correctly, the telephony origin might provide inaccurate time suggestions.
  • There might be inaccuracies introduced while obtaining the UTC time. For example, a network delay, buffering, or process scheduling might cause the UTC time to be inaccurate.
  • The reference clock used to adjust a suggestion for elapsed time since the suggestion was received might be inaccurate. For example, the UTC time might be inaccurate if an Android device can't correctly track elapsed time.

There are two main time detection origins configured for use by default in AOSP:

  • Telephony: Uses Network Identity and Time Zone (NITZ) telephony signals.
  • Network: Uses Network Time Protocol (NTP) time servers.

Both telephony and network origins require connectivity to external networks, which are not always available.

Starting with Android 12, Android also supports the following origins, which are not configured for use by default:

  • GNSS: Uses the GPS location provider to obtain a time from a GNSS source.
  • External: Generic origin that allows device manufacturers to integrate their own source of UTC time.

Time settings

Users can enable automatic time detection in System > Date and Time in the AOSP Settings app.

Automatic time detection in Settings

Figure 1. Automatic time detection in Settings.

The following table describes the user controls for time detection in the AOSP Settings app.

*On Android 11 and lower, this setting is labeled Use network-provided time

AOSP Settings location AOSP Settings name Scope Behavior
System > Date and Time Set time automatically* All users

A toggle.

When on, the device is responsible for detecting the current UTC time. When off, users are provided with controls to set the device's time manually.

When the user enters time manually, they enter their local time, not UTC time. The current UTC time is calculated by using the current time zone to derive a UTC time.

Configuration

Device manufacturers can configure the time_detector service in various ways, such as which origins to use and how to prioritize the signals from them.

Origin prioritization

From Android 12, device manufacturers can change the core/res/res/values/config.xmlconfiguration file to specify which time origins to include in automatic time detection, and the priority in which time_detector considers these origins.

For devices running Android 11 or lower, origin priority is hardcoded to["telephony", "network"], meaning that telephony suggestions are prioritized above network suggestions.

The default AOSP configuration is as follows:

<!-- Specifies priority of automatic time sources. Suggestions from higher entries in the list
     take precedence over lower ones.
     See com.android.server.timedetector.TimeDetectorStrategy for available sources. -->
<string-array name="config_autoTimeSourcesPriority">
    <item>network</item>
    <item>telephony</item>
</string-array>

In Android 12, network and telephony suggestions are configured as origins to use by default. Network time suggestions are prioritized above telephony time suggestions. Device manufacturers can change the order of the origins to revert to the behavior in Android 11 or lower, where telephony is given a higher priority.

By default, if the highest priority valid suggestion matches the device's current system clock time to within a couple of seconds, the device time won't be changed. This is to avoid creating work for installed apps that listen to the ACTION_TIME_CHANGED intent.

The allowed origin values are:

Lower time bound

Android 12 introduces a lower time bound that's used to validate time suggestions received by the time_detector service. The lower time bound value is set from the build timestamp. This works on the principle that a valid time cannot be before the device's system image was built. If a time suggestion is before the lower time bound, the time_detector service discards the suggestion because it can't be valid if the build timestamp is correct.

For devices running Android 11 or lower, the time_detector service doesn't validate incoming UTC time suggestions.

Android doesn't enforce an upper time bound.

Time debugging and testing

This section provides information about how to debug and test the behavior of the time_detector service and other components that are shared by all origins.

Interacting with the time_detector service

To view the time_detector service's configuration and state of the time_detector service, use:

adb shell cmd time_detector dump

To see additional commands for debugging and testing time zone detection, use:

adb shell cmd time_detector help

The help output also describes the device_config service properties that can be used to affect the behavior of time_detector for testing or in production. For details, see Configuring a device using the device_config service.

To validate automatic time detection, testers must be aware which origins the time_detector service is using. The following is an example of the output from the adb shell cmd time_zone_detector dump command, with the information about the current origin and service state in bold:

$ adb shell cmd time_detector dump

TimeDetectorStrategy:
  mLastAutoSystemClockTimeSet=null
  mEnvironment.isAutoTimeDetectionEnabled()=true
  mEnvironment.elapsedRealtimeMillis()=23717241
  mEnvironment.systemClockMillis()=1626707861336
  mEnvironment.systemClockUpdateThresholdMillis()=2000
  mEnvironment.autoTimeLowerBound()=2021-07-19T07:48:05Z(1626680885000)
  mEnvironment.autoOriginPriorities()=[network,telephony]
  Time change log:
    ...
  Telephony suggestion history:
    ...
  Network suggestion history:
    ...
  Gnss suggestion history:
    ...
  External suggestion history:
    ...

The information can be interpreted as follows:

Key Value
mEnvironment.isAutoTimeDetectionEnabled() Whether automatic time detection is enabled.
mEnvironment.autoTimeLowerBound() The current lower bound used to validate time suggestions.
mEnvironment.autoOriginPriorities() The origins in use and the priority order.

The time change log indicates occasions when the time_detector service has changed the current UTC time of the device.

The suggestion history information indicates what suggestions have been made by each origin.

Automatic time zone detection

This section provides an overview of the time_zone_detector service that manages automatic time zone detection, user controls in settings, telephony and location time zone detection, and testing details.

The time_zone_detector service

The time_zone_detector service, present on devices running Android 11 or higher, manages automatic time zone detection. It adjusts the device's current time zone as needed when automatic time zone detection is enabled.

When automatic time zone detection is enabled,time_zone_detector can be in one of two states: uncertain and certain.

When the time_zone_detector service is in the certain state, this means the time_zone_detector service has received strong time zone information, which can cause it to override the current time zone. When it is uncertain, this means it has received no information or only low-confidence information, which means it won't override the current time zone.

The time_zone_detector service's certain states can include ones where time_zone_detector has no time zone information to use, or where it has multiple time zones to choose between. These states are as follows:

  • A certain state with zero time zones is entered when the device is somewhere without a time zone, such as in international waters or in a disputed area. This state is similar to an uncertain state, but indicates that time_zone_detector doesn't need to take further action to try to determine the time zone.
  • A certain state with multiple time zones is entered where there is ambiguity or border conditions. In this state, if the current time zone is one of the time zones time_zone_detector is certain about, the current time zone is left as it is. Otherwise, one of the available time zones is used. This gives time_zone_detector an element of stickiness if the user has manually selected their time zone previously or as the device approaches a border.

The time_zone_detector service's certain or uncertain state is determined by time zone suggestions that are sent by an origin.

Generally, suggestions come in two types that closely match the possible states of time_zone_detector: certain and uncertain. The following are examples of suggestion types:

  • type = "uncertain", zoneIds = []

    • The origin does not know what the time zone is.
  • type = "certain", zoneIds = ["Europe/London"]

    • The origin is certain the zone is "Europe/London".
  • type = "certain", zoneIds = []

    • The origin is certain, but there is no zone ID associated with the current location.
  • type = "certain", zoneIds = ["America/Denver", "America/Phoenix"]

    • The origin is certain that the answer is one of two zones, but cannot choose between "America/Denver" and "America/Phoenix".

The time_zone_detector service treats sequences of suggestions as distinct based on their origin. Depending on the origin, suggestions might also contain metadata that indicates how certain the origin is.

The time_zone_detector service is stateful, which means that it keeps a record of the most recent suggestion made by each origin. New suggestions are sent to the time_zone_detector service if a previous suggestion is no longer correct; that is, if an origin now has a different suggestion, or if it has lost the ability to detect the time zone. The time_zone_detector service re-evaluates new and existing suggestions and updates the device state when suggestions are received.

Android supports two origins for time zone detection:

  • Telephony
  • Location

The time_zone_detector service only uses a single origin to determine the time zone. When the location origin is supported on a device, the current origin to use is determined based on the Time zone settings configured by the user. When the current origin becomes uncertain of the time zone, time_zone_detector doesn't switch to a different origin. Suggestions associated with origins besides the current origin can be held in memory by time_zone_detector, but they aren't used unless the current origin changes. When the user changes the settings for automatic time zone detection and the current origin changes, the most recent suggestion available for the new origin is used.

Time zone settings

Users can enable and configure the settings for automatic time zone detection in the AOSP Settings app.

Automatic time zone detection in Settings

Figure 2. Automatic time zone detection in Settings.

The following table describes the user controls for time zone detection in the AOSP Settings app.

*On Android 11 and lower, this setting is labeled Use network-provided time

AOSP Settings location AOSP Settings name Scope Behavior
System > Date and Time Set time zone automatically* All users

A toggle.

When on, the device is responsible for detecting the current time zone. When off, users are provided with controls to set the device's time zone manually.

System > Date and Time Use location to set time zone Current user

A toggle.

Available from Android 12. This toggle is only displayed when location time zone detection is supported on the device.

Location Use location Current user

A toggle.

Allows or prevents use of the device's location generally.

The following provides an overview of the device behavior for time zone detection given the settings chosen by the user:

  • [Date and Time] Set time zone automatically: OFF

    • The user must manually select the time zone.
  • [Date and Time] Set time zone automatically: ON

    • [Location] Use location: OFF

      • Telephony signals are used to detect the time zone. (See Note below.)
    • [Location] Use location: ON

      • [Date and Time] Use location to set time zone: ON

        • Location is used to detect the time zone.
      • [Date and Time] Use location to set time zone: OFF

        • Telephony signals are used to detect the time zone. (See Note below.)

Multiple user devices

Because several of the settings involved are scoped to the current user, the time zone detection behavior of a device can change when the current user changes on a multi-user Android device.

The Use location to set time zone toggle is scoped to the current user and isn't restricted by device policy, meaning that users can always change its value, even when the Set time zone automatically toggle is off or if other time or time zone controls are restricted by the Device Policy Controller.

Behavior when changing to and from automatic detection

When the user switches time zone detection from manual to automatic, time_zone_detector might already be certain of the current time zone. If so, as the user enables automatic detection, the device's time zone might be changed at the same time to match the time_zone_detector service's opinion.

Similarly, when the user makes a change in Settings that result in a change to the time_zone_detector service's current origin, time_zone_detector might already have received suggestions for the new origin and so the device's time might be changed to match the time_zone_detector service's opinion immediately.

Telephony time zone detection

Telephony time zone detection uses telephony signals to determine the current time zone. For more information, see Telephony Time Zone Detection.

Location time zone detection

Location time zone detection is available on Android 12 or higher. It's an optional automatic time zone detection feature that enables devices to use their location to determine the current time zone.

The location_time_zone_manager service, introduced in Android 12, runs in the system server and contains the code responsible for submitting location origin suggestions to the time_zone_detector service. For more information, see Location Time Zone Detection.

Feature adoption considerations

This section describes aspects of the location time zone detection feature to help a device manufacturer determine whether to adopt the feature on a device.

Comparing telephony and location detection

The following table provides a comparison of the advantages and disadvantages of using location rather than telephony signals for time zone detection.

Telephony detection Location detection
Correctness Varies by country.

Depends on the MCC, NITZ correctness and availability.
Depends on the feature configuration or plug-in components.

Correctness typically varies by:
  • Location provider accuracy and regularity.
  • The quality of the time zone map data.
Updatability Telephony detection relies on files contained in the updatable Time Zone Data module (com.android.tzdata APEX). Depends on the feature configuration or plug-in components.

Updatability typically depends on whether the device uses server or client time zone map data.

Note: Time zone map data isn't contained in the Time Zone Data module used to update Android's copy of TZDB and other time zone information.

The device manufacturers must also consider version consistency between the time zone rules and the time zone map data.
Power usage None or low power usage Depends on user location settings, the plug-ins being used, and typically what other apps request location.
Availability Telephony devices only. Usually requires a working SIM. Location detection depends on the location providers available.
User privacy

A user's preferred time zone is usually determined by their geographic location. Location is sensitive data. Users might be concerned about knowledge of their location being shared as part of time zone detection. Unrelated to time zone detection, all apps running on a device can read the device's current time zone without requiring an Android permission, and apps can infer an imprecise idea of the device's location from this information.

More specifically, time zone detection can work through passive or active means:

  • Passive: Something in the device's environment tells the device the time zone to use in that environment.
  • Active: The device has to work out the time zone for itself and depending on users' privacy settings and their consent, obtains the device's location to do so. It can then share its location with external services. See discussion below for details on user privacy and consent.

Passive detection, such as with the telephony origin, has no additional privacy implications for users.

Active detection, such as with the location origin, involves determining the device's location, which users might not want to agree to, and the location could be sent over a network in order to determine the time zone ID.

Android's approach to user privacy for time zone detection gives the user the ability to individually disable origins that are expected to be active. Additionally, the AOSP platform code doesn't deal directly with location itself: location detection and mapping location to time zone IDs are left to plug-in components configured by device manufacturers.

For more details on user privacy features, see Location Time Zone Detection.

Time zone debugging and testing

This section provides information about how to debug and test the behavior of the time_zone_detector service and other components that are shared by all origins.

Configuring a device using the device_config service

The device_config service is a mechanism used on Android to configure modifiable behavior using values that are typically pulled from a remote server by proprietary (non-AOSP) code. When using device_config values for testing, especially during long running manual tests, the device might synchronize the flags, which would reset the flags and clear the values set for testing.

In Android 12 or higher, to temporarily prevent flag synchronization, use:

adb shell cmd device_config set_sync_disabled_for_tests persistent

To restore flag synchronization after tests, use:

adb shell cmd device_config set_sync_disabled_for_tests none

After restoring flag synchronization, reboot the device.

For more information, use $ adb shell cmd device_config help.

Interacting with the time_zone_detector service

To view the time_zone_detector configuration and state of the time_zone_detector service, use:

adb shell cmd time_zone_detector dump

To see additional commands for debugging and testing time zone detection, use:

adb shell cmd time_zone_detector help

The help output also describes the device_config service properties that can be used to affect the behavior of the time_zone_detector service for testing or in production. For details, see Configuring a device using the device_config service.

To validate time zone detection, testers must be aware which origin the time_zone_detector is using. To understand and influence the current origin of the time_zone_detector, use one of the following options:

  • Check visually through the Settings UI. For more information, see Time zone settings.
  • Use the command line through adb:

    • To dump time_zone_detector state, use adb shell cmd time_zone_detector dump
    • To alter device setting, use other time_zone_detector commands. For more information, use adb shell cmd time_zone_detector help.

The following is an example of the output from the adb shell cmd time_zone_detector dump command, with the information about the current origin and service state in bold:

$ adb shell cmd time_zone_detector dump
TimeZoneDetectorStrategy:
  mEnvironment.getCurrentUserId()=0
  mEnvironment.getConfiguration(currentUserId)=ConfigurationInternal{mUserId=0, mUserConfigAllowed=true, mTelephonyDetectionSupported=true, mGeoDetectionSupported=true, mAutoDetectionEnabled=true, mLocationEnabled=true, mGeoDetectionEnabled=true}
  [Capabilities=TimeZoneCapabilitiesAndConfig{mCapabilities=TimeZoneDetectorCapabilities{mUserHandle=UserHandle{0}, mConfigureAutoDetectionEnabledCapability=40, mConfigureGeoDetectionEnabledCapability=40, mSuggestManualTimeZoneCapability=30}, mConfiguration=TimeZoneConfiguration{mBundle=Bundle[{geoDetectionEnabled=true, autoDetectionEnabled=true}]}}]
  mEnvironment.isDeviceTimeZoneInitialized()=true
  mEnvironment.getDeviceTimeZone()=Europe/London
  Time zone change log:
  Manual suggestion history:
...
  Geolocation suggestion history:
...
  Telephony suggestion history:
...

The information can be interpreted as follows:

Key Value
mUserConfigAllowed Whether the user is prevented from controlling date and time settings by the Device Policy Controller.
mTelephonyDetectionSupported Whether the device has telephony time zone detection.
mGeoDetectionSupported Whether the device has location time zone detection. This is the effective state based on configuration and the presence of at least one LTZP.
mAutoDetectionEnabled Whether automatic time zone detection is enabled.
mLocationEnabled The master location toggle.
mGeoDetectionEnabled The origin switch: `false` indicates the telephony origin, and `true` indicates the location origin.

The suggestion history information indicates what suggestions have been made through Settings (manual), and by the telephony and location origins.