I am getting result correct for some dates and I am not getting it correct for some of date.it converts time perfectly , but for some date it converts year to the next year.
following are some observation.
firstDate = 2008-12-27 17:17:58 +0530. firstUtcDate = 2008-12-27 11:47:58. secondDate = 2008-12-29 16:30:00 +0530. secondUtcDate = 2009-12-29 11:00:00 //the year has been changed. thirdDate = 2008-12-29 17:00:00 +0530 thirdUtcDate = 2009-12-29 11:30:00 //again the year has been changed.
Imported from the Apple Support Forums via the Wayback Machine 🔗
It certainly looks like a bug. In 10.4 Apple revamped NSDateFormatter and based it on some open-source library. They also continue to support the old behavior for backwards compatibility. The compiler tries to pick the correct API to use based on your target OS.
The errors you are seeing could come from not fully understanding the new NSDateFormatter and using it incorrectly. I know I certainly don't understand it - two simultaneous, but incompatible APIs for the same class???? Also, the errors could come from bugs in the open-source library.
I took your example and switched to the old-style formatting and got answers that weren't as incorrect. They were still wrong, but off by only a few hours instead of a year. In addition, I am not even sure if I am using the old-style formatting correctly because Apple's documentation is self-contradictory.
This is the second date formatting thread I've been involved with here in the forums. If I needed to handle dates, I think I would write my own class. Apple's date classes are a disaster.
0
ericmeyers·
Imported from the Apple Support Forums via the Wayback Machine 🔗
etresoft wrote:
Apple's date classes are a disaster.
I'll second that.
Eric
0
Charles Minow·
Imported from the Apple Support Forums via the Wayback Machine 🔗
xmax wrote:
I am using following function to convert NSDate in "UTC" date.
Try changing the year formatting arguments to " yyyy". " YYYY" means something else besides the year: Year (of "Week of Year"), used in ISO year-week calendar. May differ from calendar year.
See the
Unicode docs for an explanation.
charlie
0
xmax·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Yes, I done with "yyyy" . and it worked.
So, This is the only way to convert the NSdate in utc date.
is There any other way to derive the utc date for NSDate ?
---------
Thanks.
xmax
0
ericmeyers·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Good catch Charles.
Eric
0
Charles Minow·
Imported from the Apple Support Forums via the Wayback Machine 🔗
xmax wrote:
So, This is the only way to convert the NSdate in utc date.
is There any other way to derive the utc date for NSDate ?
I think that's the only way, and really only if you want to display it. I've also been trying to work with NSDate to get the UTC. But I wanted integers for day, month, year, hour, minute, and seconds for a calculation. I finally gave up and went with time and gmtime from standard C libraries.