Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set date/time using ADB shell

Tags:

android

adb

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?

like image 423
Abraão Caldas Avatar asked Oct 21 '13 14:10

Abraão Caldas


2 Answers

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" 
like image 126
Alex P. Avatar answered Oct 08 '22 17:10

Alex P.


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' 
like image 45
Amir Uval Avatar answered Oct 08 '22 18:10

Amir Uval