77

Why doesn't the Android emulator's clock match the host system clock? It's not a time zone difference--it's always off by several minutes.

Is there a way to synchronize them besides manually setting the emulator's time?

6
  • 1
    Can you set the time via the settings the same way you can on a device?
    – FoamyGuy
    Commented Jun 21, 2012 at 23:37
  • @Sam : Urrrm, if I understand the OP correctly, I think he means the 'Clock' as in the thing which shows the current time on the screen.
    – Squonk
    Commented Jun 21, 2012 at 23:45
  • Sorry, I don't have enough reputation yet to post a comment on the asker's question, or else I would. When you launch your emulator through the Android AVD Manager, do you have save to snapshot or launch from snapshot enabled?
    – avoyles
    Commented Jun 21, 2012 at 23:49
  • @Squonk Seems these "Clock things" are confusing, here's a screenshot with the emulator's UTC (Universal Time) and my host system's time.
    – Sam
    Commented Jun 22, 2012 at 0:58
  • 3
    @Sam : I think you missed my point. The OP states "it's often off by several minutes." which clearly isn't a time-zone variation from UTC. You might create AVDs which default to UTC but I set mine to my own locale which means the AVD shows my time-zone and not UTC.
    – Squonk
    Commented Jun 22, 2012 at 8:18

8 Answers 8

65

I had the same problem and got it resolved by just restarting the emulator using emulator power button.

4
  • 7
    I needed a Cold Boot from AVD manager but then this worked for me Commented Aug 10, 2021 at 15:45
  • 19
    you can use command adb reboot
    – diewland
    Commented Oct 14, 2021 at 7:38
  • I used " wipe data " using AVD manager and then did a " Cold Boot Now " and it worked! Commented Jan 7, 2022 at 19:52
  • Thanks @Balaramakrishna Rachumallu, Working for me after restart emulator Commented Dec 13, 2023 at 10:55
24

I believe there is no way to synchronize the time. The default image of the emulator sets to UTC/GMT (+00:00). However you can change it to your own.

Here is an image on how to do so: First un-check the "Automatic Time Zone" (red arrow) then click on the "Selected Time Zone" (green arrow) and finally select your time zone and it should match the one on your system (yellow arrow). timezone screen shots

6
  • even if the minutes are off on his setup as he seems to indicate, it should still be possible to fix it this way by taking off automatic date&time and manually setting both hours and minutes to whatever you please. Including whatever the system time is.
    – FoamyGuy
    Commented Jun 22, 2012 at 0:14
  • yes :) as you mentioned it would be possible to "synchronize" it by setting it manually.
    – Raykud
    Commented Jun 22, 2012 at 0:17
  • 3
    I stated in the question that this is not a timezone problem, that it is off by several minutes (not hours). Commented Jun 22, 2012 at 12:21
  • This worked for me. Although I admit, my issue was not exactly the same--just a timezone problem.
    – SMBiggs
    Commented Sep 28, 2014 at 17:13
  • @JeffAxelrod: Apparently, your question got a life of its own, independent of your original intentions: People like me, who do have a timezone problem, get your question as the top Google result, get helped by the first answer and upvote it. I am tempted to modify your question to match the answers, but I would not want to do that without your consent.
    – Heinzi
    Commented May 29, 2019 at 14:02
12

On AndroidTV API 28 simulator, this works (GNU/Linux, and some Mac) :

adb shell su root date $(date +%m%d%H%M%Y.%S)

The host timezone should match your AndroidTV timezone.

2
10

The date command has changed in newer androids since the other answers. You must have root, -s is not recognized and the set format has changed.

I've had luck using adb shell su root date -u @$(date +%s.%N), which uses @ to set it using UNIX timestamp seconds with nanosecond precision. -u is required if you have changed the timezone for some reason, even though timestamps should not have a time zone!

1
  • 4
    Thank you. This is the only answer that has worked in recent times. For macOS, just skip the nanoseconds, so: adb shell su root date -u @$(date +%s)
    – mtkopone
    Commented Nov 7, 2018 at 7:09
9

If there are some discrepancies between the AVD and host times, mainly after restarting from a snapshot you can use adb shell date to check and/or set the date just after you launched the emulator.

2
  • 1
    adb shell date is a effective way though it can not solve the issue completely
    – Ninja
    Commented Jan 12, 2017 at 7:18
  • date: cannot set date: Operation not permitted :(. emulator version 34.1.20.0, using API 34 arm64-v8a google play image.
    – Tom
    Commented May 2 at 1:45
5

As I've got this as top link in google :)

On windows you can get right time by issuing

adb shell date -s %date:~10,4%%date:~4,2%%date:~7,2%.%time:~0,2%%time:~3,2%%time:~6,2%

-s value should be in format: YYYYMMDD.hhmmss

On systems that have different time format, portion with windows shell args will be different!

You can test out in cmd.exe:

> echo %date%
Thu 01/22/2015

To output YYYY part use: %date:[position of char. 0-based],[length]%

On linux:

adb shell date -s $(date +%Y%m%d.%H%M%S)
3
  • on mac terminal: works only on emulator or rooted device. adb shell su root "date $(date +%m%d%H%S)"
    – Thupten
    Commented Jun 4, 2017 at 19:30
  • 1
    @Thupten on macOS your command gives me error /system/bin/sh: su: not found Commented May 30, 2018 at 17:51
  • @Thupten has a slight mistake, it should be: adb shell su root "date $(date +%m%d%H%M)" Commented Jan 25, 2019 at 19:27
1

On Windows, you need to put quote around the datetime string to avoid error when the parsing returns a space in front of a digit.

The complete syntax would be:

adb shell date -s '%date:~10,4%%date:~4,2%%date:~7,2%.%time:~0,2%%time:~3,2%%time:~6,2%'
1

Mackbook Air M2 - Android Studio Flamingo-emulator API 33.Had the same issue.Cold reboot after setting time zone of emulator worked for me.

1
  • Linux (Fedora) had the same issue and solved by the same method.
    – innomatic
    Commented Mar 19 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.