Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...