如何在iPhone模拟器中更改时间和时区?


当前回答

在更改时区时,我发现最简单的方法是点击菜单栏中的时钟。然后选择“打开日期和时间首选项”,然后选择时区选项卡。

或者选择“System Preferences -> Date and Time”,选择“Time Zone”页签。

只是给那些不知道如何使用OSX的人一个提示。

其他回答

以下是至少在iOS 13和Xcode 11中可用的解决方案。(未对以前的版本进行测试) [编辑]这只会改变评论中的状态栏!

默认情况下,iOS模拟器显示Mac上的任何时间,但是,你可以使用Xcode的命令行在终端中使用以下命令来覆盖它:

xcrun simctl status_bar "iPhone 11 Pro Max" override --time '9:41'

将模拟器名称替换为要更改的设备。

对于状态栏,你有这个覆盖:

You may specify any combination of these flags (at least one is required):

--time <string>
     Set the date or time to a fixed value.
     If the string is a valid ISO date string it will also set the date on relevant devices.
--dataNetwork <dataNetworkType>
     If specified must be one of 'wifi', '3g', '4g', 'lte', 'lte-a', or 'lte+'.
--wifiMode <mode>
     If specified must be one of 'searching', 'failed', or 'active'.
--wifiBars <int>
     If specified must be 0-3.
--cellularMode <mode>
     If specified must be one of 'notSupported', 'searching', 'failed', or 'active'.
--cellularBars <int>
     If specified must be 0-4.
--batteryState <state>
     If specified must be one of 'charging', 'charged', or 'discharging'.
--batteryLevel <int>
     If specified must be 0-100.

时间可以是任何字符串。但如果你想让设备显示日期,你需要使用ISO格式。 例如,有效的ISO日期字符串应该是'2007-01-09 t10 . 41:00+01:00'

否则,您可以使用时间参数作为字符串,它将显示您传递的任何内容。

感谢Paul Hudson的原创文章,这里是链接!

在更改系统日期时间首选项后,我不得不选择硬件>重置所有内容和设置。 只有在10.3版(SimulatorApp-880.5 CoreSimulator-681.5.4)中,我才这样做。

我猜它使用您的系统时区,所以在系统首选项中更改TZ可能会奏效

在更改系统日期时间首选项后重新启动模拟器,您将看到反映的更改。这对我很管用。

在更改时区时,我发现最简单的方法是点击菜单栏中的时钟。然后选择“打开日期和时间首选项”,然后选择时区选项卡。

或者选择“System Preferences -> Date and Time”,选择“Time Zone”页签。

只是给那些不知道如何使用OSX的人一个提示。