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
I didn't have any issue with Android 5, most answers I found without su in the command works.
Android 6 is the one that got my attention.
On Android 6, it didn't give me error, it just didn't set it right, it will set it back to what it was before the command. I also ran into /system/bin/sh: su: not found errors
when I tried this https://stackoverflow.com/a/43481982/3922705
and this https://stackoverflow.com/a/19497572/3922705
After all the try-and-error sessions, I figured it out.
This is the date format I use MMDDhhmm[[CC]YY][.ss]
adb shell date '0739010002017.00'
This command didn't work, initially, in order work, it didn't work by itself.
I used this 3 steps and it works for me.
First, adb shell settings put global auto_time 1
(Turn on Automatic date & time)
Second, adb shell date '0739010002017.00'
( set time you want )
Third, adb shell settings put global auto_time 0
(Turn off Automatic date & time)
Noted: For my specific project, I can not rely on the network-provided and GPS-provided time. That's why I have the third command. which turn off the feature.
To make this work on my Xperia S, I had to break the commands as follows:
> adb shell
# su -
# date /* see current date */
# date -s YYYYmmdd
Motive: my device had reverted to the beginning of Linux time, and I wasn't particularly worried with time, all I wanted was to set the correct date -- which, BTW I couldn't do through system settings because my custom MIUI ROM kept crashing...
Expanding on @uval's answer, you can use the following to update the date and time on the android device based on the time on your Windows machine:
set dateYYYY=%date:~10,4%
set dateMM=%date:~4,2%
set dateDD=%date:~7,2%
set timeHH=%time:~0,2%
set timeMM=%time:~3,2%
set timeSS=%time:~6,2%
adb shell su -c date %dateMM%%dateDD%%timeHH%%timeMM%%dateYYYY%.%timeSS%
adb shell su -c am broadcast -a android.intent.action.TIME_SET
Tested on a rooted Android 6.0 device and a Windows 10 PC.
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'
The correct format that has worked for me is yyyyMMddHHmm.ss
On some devices like RTAndroid maybe it works too:
adb shell "su 0 date `date +%m%d%H%M%Y.%S`"