11

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

0

5 Answers 5

32

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)

Sign up to request clarification or add additional context in comments.

6 Comments

Hi, is it possible to get the time from a windows machine and set it as android time ?
Sorry, not a Windows user
hi its nice,there any method to exicute this command on my application apk using java code
@harsha.kuruwita you could run a shell command within an app but need a rooted device
@harsha.kuruwita this post explains how to change the system time
|
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.

Comments

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

2 Comments

When I try adb shell date 1319124916 I get this time 1319124916 -> 1319124916.0 settimeofday failed Bad file number
On Linux I use: adb shell date -s `date "+%Y%m%d.%H%M%S"`
1

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`

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.