Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How-to set Android device date/time programmatically [duplicate]

BACKGROUND

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

QUESTION(S)

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

like image 616
celoftis Avatar asked Aug 17 '11 14:08

celoftis


2 Answers

You can use the next command:

adb shell date -s YYYYMMDD.HHmmss

example:

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)

like image 152
JuanMa Cuevas Avatar answered Oct 17 '22 03:10

JuanMa Cuevas


I made this perl script to handle this problem:

clock.pl

use Time::localtime;
$_=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.

like image 39
António Almeida Avatar answered Oct 17 '22 03:10

António Almeida