Set date/time using ADB shell

2019-01-14 03:30发布

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?

标签: android adb
8条回答
狗以群分
2楼-- · 2019-01-14 03:49

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`"
查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-14 03:58
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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-14 04:01

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'
查看更多
我只想做你的唯一
5楼-- · 2019-01-14 04:02

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...

查看更多
Juvenile、少年°
6楼-- · 2019-01-14 04:03

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"
查看更多
在下西门庆
7楼-- · 2019-01-14 04:10

On some devices like RTAndroid maybe it works too:

adb shell "su 0 date `date +%m%d%H%M%Y.%S`"
查看更多
登录 后发表回答