Answer the question
In order to leave comments, you need to log in
NSDate in iOS 4.2?
I noticed that [NSDate date] returns the date without regard to the time zone. For example, I have ("Europe / Kiev")
At 14:00 hours, in the log 12:00
I used this crutch:
<font color="black"><ol> <li> </li> <li><font color="#002200">+</font> <font color="#002200">(</font><font color="#400080">NSDate</font><font color="#002200">*</font><font color="#002200">)</font>currentDate <font color="#002200">{</font> </li> <li> <font color="#11740a"><i>// Get conversion to months, days, hours, minutes</i></font></li> <li> <font color="#a61390">unsigned</font> <font color="#a61390">int</font> unitFlags <font color="#002200">=</font> NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;</li> <li> <font color="#400080">NSDateComponents</font> <font color="#002200">*</font>dateComponents <font color="#002200">=</font> <font color="#002200">[</font><font color="#002200">[</font><font color="#400080">NSCalendar</font> currentCalendar<font color="#002200">]</font> components<font color="#002200">:</font>unitFlags fromDate<font color="#002200">:</font>self<font color="#002200">]</font>;</li> <li> <font color="#002200">[</font>dateComponents setTimeZone<font color="#002200">:</font><font color="#002200">[</font><font color="#400080">NSTimeZone</font> timeZoneWithAbbreviation<font color="#002200">:</font><font color="#bf1d1a">@</font><font color="#bf1d1a">"GMT"</font><font color="#002200">]</font><font color="#002200">]</font>;</li> <li> <font color="#400080">NSDate</font> <font color="#002200">*</font>date <font color="#002200">=</font> <font color="#002200">[</font><font color="#002200">[</font><font color="#400080">NSCalendar</font> currentCalendar<font color="#002200">]</font> dateFromComponents<font color="#002200">:</font>dateComponents<font color="#002200">]</font>;</li> <li> <font color="#a61390">return</font> date;</li> <li><font color="#002200">}</font></li> <li> </li> </ol></font>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question