I'm trying to debug code that makes pretty heavy use of dates which has me comparing tons of different NSDate values in the debugger. The debugger is displaying those dates in UTC format--for example:
date1 = (NSDate *) 0x01b11460 @"2012-02-15 18:55:00 +0000"
It would be a lot easier for me if it would show them in my local timezone as that is what the test code I'm debugging seems to be using.
I do have feeling that I'm missing something much more basic here so I'm hoping someone can enlighten me. Thanks in advance.
In the end, what worked best was in fact adding a Category for NSDate that just overrides the
description
method to return a string that represents the NSDate in my current timezone. I also made it DEBUG only as I really just need this override in place when debugging.Here's the .h file I used:
and the .m file:
Thanks to Jim Hayes and jrturton for the discussion and ideas that led to this answer.
Just did the same thing, however instead of systemTimeZone I used localTimeZone (see the docs as to why it is slightly better). Also I noticed you are alloc'ing the dateFormatter object but never releasing it which is a leak.
Here's my category method:
While a little "hackish" you can create a subclass of NSDate and override just the
method to return a date formatted however you want.
The debugger isn't doing any special decoding for you, it's just calling the "description" method of the object it wants to display. A handy trick... (Which is why all my objects publish a concise description suitable for viewing in a debugger.)