Home » Android » adb – How-to set Android device date/time programmatically

adb – How-to set Android device date/time programmatically

Posted by: admin May 14, 2020 Leave a comment



I am working on a project using the Wi-fi only version of the Samsung Galaxy tab (7″). On some of the devices we are seeing the date/time on the device getting reset (don’t know why) to some date in the past (like 1/1/2000).


How can I programmatically reset the device date/time? I’d prefer to use some adb shell command if possible (my shell scripting is rusty). If there is no shell command that can accomplish this, is there a way to accomplish this by writing and installing an app (seems like a security violation)?

How to&Answers:

You can use the next command:

adb shell date -s YYYYMMDD.HHmmss


adb shell date -s 20120423.130000

sets the date to Mon Apr 23 13:00:00 CEST 2012 (my phone is on CEST time zone)


I made this perl script to handle this problem:


use Time::localtime;
system'adb','shell','date -s',sprintf("%04d%02d%02d.%02d%02d%02d",$_->year+1900,$_->mon+1,$_->mday,$_->hour,$_->min,$_->sec)

Call it using cmd (windows) or terminal (mac):

perl < clock.pl

The android clock will be instantly updated with your machine time.


Use the shell’s ‘date’ command. With an argument of unix epoch time (i.e. seconds since 1/1/70) it sets the device’s clock, e.g. ‘adb shell date 1318349236’.

You can get the current timestamp in seconds with ‘adb shell date +%s’. If you have busybox, the date command is more capable, and you can get your arbitrary desired date in seconds with ‘busybox date +%s -d “2010-01-01 12:34:56″‘


Change Date based on Your system date

Change Date same as system

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

Change Date to tomorrow:

adb shell date -s `date --date='1 day' +%G%m%d.%H%M%S`

Change Date to Tomorrow 12 AM

adb shell date -s `date --date='1 day' +%G%m%d.000000`

Change Date to Yesterday

 adb shell date -s `date --date='1 day ago' +%G%m%d.%H%M%S`

Change Date to week ago

adb shell date -s `date --date='1 week ago' +%G%m%d.%H%M%S`


I am using the following commands to correctly format date and time in windows and the set system time on android

set datetimef=%date:~3,2%%date:~0,2%%time:~0,2%%time:~3,2%%date:~-4%.%time:~6,2%
adb shell date -d %datetimef%

This does set the unix system time of Android but does not change the hardware clock. The time displayed by android gui is also not influenced this way.

I guess hwclock command should be used to update the hardware clock, but this does not execute due to permission errors.