How to change time and time zone in iPhone simulator?

How to change time and time zone in iPhone simulator?

+124
timezone objective-c xcode ios-simulator
Nov 09 '09 at 8:09
source share
6 answers

I assume it uses the time zone of your system, so changing the TZ in the system settings is likely to do the trick

Screenshot for description

+188
Nov 09 '09 at 8:11
source share

Restart the simulator after changing the time settings in the system, and you will see that the changes are reflected. It worked for me.

+35
Mar 30 '13 at 8:40
source share

It would be helpful if Apple provided the "Simulate Date" as they provided the "Simulate Location" menu. What I do is set by a breakpoint immediately after receiving the date (storing it in a variable) and then changing the value. Or just change the place where I check the date change and return it true.

+33
26 Dec '14 at 18:00
source share

When changing the time zone, I found the easiest way to do this by clicking the clock in the menu bar. Then select "Open Date and Time Preferences", then select the "Time Zone" tab.

Alternatively, System Preferences → Date and Time and select the Time Zone tab.

Just a pointer for anyone who may not know their way in OSX.

+5
Jan 07 '14 at 8:21
source share

This is an old thread, but it is closest to my question. I need to simulate a time zone for Europe, this method works for me. Scroll to "TimeZone" instead of "Date & Time". Uncheck "Set the time zone automatically using the current location" and slide the vertical panel of the rectangle (with a blue dot on it) to simulate your system time.

enter image description here

+4
Nov 28 '15 at 4:20
source share

I proposed an automatic solution to the problem of changing the time, which includes the hacked swackling method: https://stackoverflow.com/a/212618/ I assume that this should also work to change the time zone accordingly.




I needed to check the application automatically, which required a sys time change. I did what Tom suggested: the happy hacker swizzling method.

For demonstration purposes, I only change [NSDate date] , but not [NSDate dateWithTimeIntervalSince1970:] .

First you need to create your own class method, which will be used as the new [NSDate date]. I implemented it to just shift time to constant time.

 int timeDifference = 60*60*24; //shift by one day NSDate* (* original)(Class,SEL) = nil; +(NSDate*)date{ NSDate* date = original([NSDate class], @selector(date)); return [date dateByAddingTimeInterval:timeDifference]; } 

It is still pretty easy. Now comes an interesting role. We get methods from both classes and the exchange implementation (it worked for me in AppDelegate, but not in my UITests class). To do this, you will need to import objc/runtime.h .

 Method originalMethod = class_getClassMethod([NSDate class], @selector(date)); Method newMethod = class_getClassMethod([self class], @selector(date)); //save the implementation of NSDate to use it later original = (NSDate* (*)(Class,SEL)) [NSDate methodForSelector:@selector(date)]; //happy swapping method_exchangeImplementations(originalMethod, newMethod); 
+2
Jan 14 '16 at 15:28
source share



All Articles