Set date/time using ADB shell

I'm trying to set the date/time using the ADB shell but the shell only returns the current time.

I've tried:

adb shell date -s YYYYMMDD.HHmmss

and unix time like:

adb shell date 1318349236

any ideas?


Solution 1:

To save storage space Android like many other embedded systems uses multi-call binaries to implement its basic command line tools like date.

Android device may include either toolbox or toybox (or both) binary depending on the version. You can check which implementation of the date tool available on your device by running toolbox date and toybox date commands. Then you can use the one which prints out the current date. For example for an Android 6.0+ device it might look like:

$ adb shell toybox date
Mon Jul 31 21:09:28 CDT 2017

$ adb shell toolbox date
date: no such tool

To set date and time using toolbox date use YYYYMMDD.HHmmss format:

adb shell "su 0 toolbox date -s 20161231.235959"

In case of toybox date use MMDDhhmm[[CC]YY][.ss] format:

adb shell "su 0 toybox date 123123592016.59"

Solution 2:

Android 6.0 has a new date format:

Default SET format is "MMDDhhmm[[CC]YY][.ss]", that's (2 digits each)
month, day, hour (0-23), and minute. Optionally century, year, and second.

And setting with -s no longer works. This is the updated set command:

Example of the updated command:

(while inside an adb shell)

date 060910002016.00                              

will result in:

Thu Jun  9 10:00:00 GMT 2016

Notice: The command will not be visible immediately on the device because it doesn't trigger any time change broadcast, But it will be visible within a minute.

To work around that, you can append this broadcast manually this way:

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

To call this with an adb command:

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

Solution 3:

You have to put date value if you want to change it.

-s changes SET format. Default SET format is MMDDhhmm[[CC]YY][.ss].

I successfully tested the following commands:

adb root
adb shell "date `date +%m%d%H%M%Y.%S`"

Solution 4:

adb shell date -s `date +%G%m%d.%H%M%S`

At first it gets the current date of your machine and set it on the android target. This approach should work on Linux/Mac/Cygwin.