Android 仿真器的时钟与主机系统时钟不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11148309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:09:05  来源:igfitidea点击:

Emulator's clock doesn't match the host system clock

androidandroid-emulatorclockavd

提问by Jeff Axelrod

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.

为什么 Android 模拟器的时钟与主机系统时钟不匹配?这不是时区差异——它总是相差几分钟。

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

除了手动设置模拟器的时间之外,还有其他方法可以同步它们吗?

回答by Raykud

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.

我相信没有办法同步时间。模拟器的默认图像设置为 UTC/GMT (+00:00)。但是,您可以将其更改为您自己的。

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

这是有关如何执行此操作的图像:首先取消选中“自动时区”(红色箭头),然后单击“所选时区”(绿色箭头),最后选择您的时区,它应该与上的时区匹配您的系统(黄色箭头)。 时区屏幕截图

回答by Diego Torres Milano

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

如果 AVD 和主机时间之间存在一些差异,主要是在从快照重新启动之后,您可以adb shell date在启动模拟器后立即检查和/或设置日期。

回答by Artem L

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

因为我把它作为谷歌的顶级链接:)

On windowsyou can get right time by issuing

Windows 上,您可以通过发出正确的时间

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

-svalue should be in format: YYYYMMDD.hhmmss

-s值应采用以下格式: YYYYMMDD.hhmmss

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

在具有不同时间格式的系统上,带有 windows shell args 的部分会有所不同!

You can test out in cmd.exe:

您可以测试cmd.exe

> echo %date%
Thu 01/22/2015

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

要输出 YYYY 部分,请使用: %date:[position of char. 0-based],[length]%

On linux:

linux 上

adb shell date -s $(date +%Y%m%d.%H%M%S)

回答by Simon Buchan

The datecommand has changed in newer androids since the other answers. You must have root, -sis not recognized and the set format has changed.

date自其他答案以来,该命令在较新的机器人中发生了变化。您必须有root,-s无法识别并且设置格式已更改。

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. -uis required if you have changed the timezone for some reason, even though timestamps should not have a time zone!

我很幸运使用adb shell su root date -u @$(date +%s.%N),它用于@使用具有纳秒精度的 UNIX 时间戳秒来设置它。-u如果您出于某种原因更改了时区,则是必需的,即使时间戳不应该有时区!

回答by user4906642

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.

在 Windows 上,您需要在日期时间字符串周围加上引号以避免在解析返回数字前面的空格时出错。

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

回答by Fred

On AndroidTV API 28 simulator, this works (linux) :

在 AndroidTV API 28 模拟器上,这有效(linux):

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

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

The host timezone should match your AndroidTV timezone.

主机时区应与您的 AndroidTV 时区相匹配。

回答by Balaramakrishna Rachumallu

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

我遇到了同样的问题,只需使用模拟器电源按钮重新启动模拟器即可解决。