简体   繁体   English

在 XCode 模拟器上更改系统日期

[英]Change system date on XCode Simulator

I'm trying to figure out how to specify a certain date on an XCode simulator, just like how you can simulate a location.我试图弄清楚如何在 XCode 模拟器上指定某个日期,就像你如何模拟一个位置一样。 I need to specify a date to test a sunrise/sunset calculation, which varies by date.我需要指定一个日期来测试日出/日落计算,该计算因日期而异。

I see you can set a time zone environment variable in the build scheme like this .我看到您可以像这样在构建方案中设置时区环境变量。

Is it possible to set a specific date that way?是否可以这样设置特定日期? If not, is there another way to set the date?如果没有,还有其他方法可以设置日期吗?

Numerous ways to create a Date object...创建日期的多种方法 object...

Here's one method using DateComponents -- which may work well for your testing:这是使用DateComponents的一种方法——它可能适用于您的测试:

    var dc = DateComponents()

    dc.year = 2022
    dc.month = 8
    dc.day = 25
    dc.hour = 12
    dc.minute = 34
    dc.second = 55

    let testDate = Calendar.current.date(from: dc)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM