68

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?

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
  • 1
    Can you set the time via the settings the same way you can on a device? – FoamyGuy Jun 21 '12 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 Jun 21 '12 at 23:45
  • @Squonk Seems these "Clock things" are confusing, here's [a screenshot](http://i.imgur.com/jBGmy.jpg) with the emulator's UTC (Universal Time) and my host system's time. – Sam Jun 22 '12 at 00:58
  • 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 Jun 21 '12 at 23:49
  • 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 Jun 22 '12 at 08:18
  • Which operating system are you using? I had exactly the same issue and I fixed it via a script I installed in my `crontab`. This can be easily done in MacOS (as I did) or in Linux systems. – Kubuntuer82 Jul 01 '19 at 07:21

8 Answers8

58

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

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

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
Raykud
  • 2,488
  • 3
  • 21
  • 41
  • 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 Jun 22 '12 at 00:14
  • yes :) as you mentioned it would be possible to "synchronize" it by setting it manually. – Raykud Jun 22 '12 at 00:17
  • 3
    I stated in the question that this is **not** a timezone problem, that it is off by several minutes (not hours). – Jeff Axelrod Jun 22 '12 at 12:21
  • This worked for me. Although I admit, my issue was not exactly the same--just a timezone problem. – SMBiggs Sep 28 '14 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 May 29 '19 at 14:02
  • @Heinzi LOL, no, I wasn't asking about how to synchronize time zones. So much so that I bolded the question to indicate that specifically. – Jeff Axelrod Aug 04 '19 at 20:10
11

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.

FredG
  • 712
  • 7
  • 10
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.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
9

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!

Simon Buchan
  • 12,707
  • 2
  • 48
  • 55
  • 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 Nov 07 '18 at 07:09
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)
Artem L
  • 10,123
  • 1
  • 20
  • 15
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%'
0

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

Abhay
  • 1
  • 1