Monday, January 21, 2008

Setting emulator time in Android


Setting the emulator time in android is fairly easy using the date command inside the android emulator image. If you are developing and testing a time related application you may found useful to change system time to force some events to happen, like an appointment alarm.

To do this, just use

$ adb shell date secs


where secs is seconds since 1970-01-01 00:00:00 UTC.

Emulator time is updated every minute, so you have to wait until the display is update, however system time has already been changed.

If you are in Linux and want to obtain secs for an arbitrary date


$ date --date="2008-01-31 17:46:59" +%s


or as a one-liner

$ adb shell date $(date --date="2008-01-31 17:46:59" +%s)


notice that we are using two different date commands, one from the android platform and the other from our Linux system. If you are using Windows or OSX, I'm sure you can find a similar way of doing this.

There are other alternatives, like installing Busybox in the system image, but this is left for another article. Stay tuned.

6 comments:

Learn Android said...

Hi,
I have a query regarding the date and time settings.Kindly help me over it.

I like to know
How actually the time is synchronized in the DEV PHONE (Not the Emulator) ....

What actually it does when clicked on ,,,

Settings--->Data&Time--->Automatic.

What does this mean "Use network provided values"....Is it referring to the GPS to get the actual time....

Kindly help on this...

Thank you,
regards,
sheik

Learn Android said...

Hi,
I have a query regarding the date and time settings.Kindly help me over it.

I like to know
How actually the time is synchronized in the DEV PHONE (Not the Emulator) ....

What actually it does when clicked on ,,,

Settings--->Data&Time--->Automatic.

What does this mean "Use network provided values"....Is it referring to the GPS to get the actual time....

Kindly help on this...

Thank you,
regards,
sheik

Diego Torres Milano said...

I think that Settings--->Data&Time--->Automatic on the G1 synchronizes the time with the mobile network you are connecting to, however there's not enough documentation on how it is done (or at least I couldn't find it).
There are some issues reported with RC33 showing some difference (measure in minutes) from the real time.
If you are suffering form this problem you should contact technical support.

Hope this helps.

Learn Android said...

thank you for replying...

Ur answer definitely answers part of the question..I refer another link that i like to share with u (from T-Mobile)
http://support.t-mobile.com/knowbase/root/public/tm52540.htm

Thanks again...Keep blogging.
regards
sheik

Unknown said...

Setting stuff just like time to such an advanced affair as a Android must be a bit complicated thing to accomplish.
Thanks a lot for this pretty useful tutorial. I will try to forget about Generic Viagra in order to focus on this matter

admin said...

The closing paragraph tells it all in my opinion. I have to say that I agree with it, and probably the most great factor about it is that you left it open ended…this exhibits that you are ready to draw in new and completely different opinions and that you're ultimately very interested to see people getting concerned in the subject. So, any different opinions?

how to get rid of cellulite