10

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

zw324
  • 26,764
  • 16
  • 85
  • 118
celoftis
  • 363
  • 3
  • 6
  • 18

5 Answers5

31

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)

JuanMa Cuevas
  • 1,162
  • 9
  • 22
2

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.

António Almeida
  • 9,620
  • 8
  • 59
  • 66
1

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"'

Bill
  • 37
  • 2
  • 1
    When I try adb shell date 1319124916 I get this time 1319124916 -> 1319124916.0 settimeofday failed Bad file number – celoftis Oct 20 '11 at 15:24
  • 1
    On Linux I use: adb shell date -s \`date "+%Y%m%d.%H%M%S"\` –  Mar 29 '13 at 18:25
0

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.

Georg W.
  • 1,292
  • 10
  • 27
0

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`
Lava Sangeetham
  • 2,943
  • 4
  • 38
  • 54