Setting Date and Time on Android Devices Using ADB Shell

Setting Date and Time on Android Devices Using ADB Shell

30 November 2024 Stephan Petzl Leave a comment Tech-Help

When working with Android devices, particularly in development and testing environments, you may encounter the need to set the date and time programmatically. This can be accomplished using ADB (Android Debug Bridge) shell commands. Here, we provide a comprehensive guide to help you achieve this task effectively.

Understanding the ADB Shell Date Command

To set the date and time on an Android device using ADB shell, it’s crucial to understand the available commands and formats. Android devices utilize either toolbox or toybox binaries, which provide different implementations for command-line tools like date. Depending on the Android version, the format for setting the date and time may vary.

Checking Available Binaries

  • To determine which implementation is available on your device, you can run:
    • adb shell toolbox date
    • adb shell toybox date
  • The command that returns the current date indicates the available binary.

Setting Date and Time with Toolbox

If your device uses the toolbox binary, you can set the date and time using the following command:

adb shell "su 0 toolbox date -s YYYYMMDD.HHmmss"

Setting Date and Time with Toybox

For devices with the toybox binary, use this format:

adb shell "su 0 toybox date MMDDhhmm[[CC]YY][.ss]"

Example Commands

Let’s look at a practical example for an Android 6.0+ device using the toybox binary:

adb shell "su 0 toybox date 123123592016.59"

This command sets the date to December 31, 2016, at 23:59:59.

Ensuring Immediate Update

Sometimes, changes to the date and time may not reflect immediately due to the lack of a broadcast trigger. To ensure the device updates promptly, append a broadcast command:

adb shell 'date 060910002016.00 ; am broadcast -a android.intent.action.TIME_SET'

Additional Resources

If you encounter issues setting the date and time, or if you are dealing with specific device requirements, we recommend exploring our related articles:

Enhancing Testing Efficiency with Repeato

For developers and testers who routinely need to manipulate device settings, tools like Repeato can significantly enhance efficiency. Repeato is a no-code test automation tool for iOS and Android, allowing you to create, run, and maintain automated tests swiftly. With its ability to execute ADB commands via script steps, Repeato ensures precise timing and sequencing of commands, simplifying tasks such as setting the device’s date and time. Discover more about how Repeato can streamline your testing processes by visiting our documentation.

Like this article? there’s more where that came from!