Hey everyone,
I need to convert the following format into a new format using NSDateFormatter. I am quite seasoned with this but for some reason I can’t remember the correct formatting information for this foramt:
‘Fri, 25 Mar 2011 10:16:00 -0700’.
I tried using this format:’aaa, dd bbb YYYY HH:MM:SS ZHHMM’ but it doesn’t work, gives me a date way in the past.
I also need to convert it into the Eastern Time Zone when creating a new date. It says ‘+0000’ but what is that normalized to?
Any help appreciated,
Thanks,
~Arash
Typically when you’re getting date strings like that, you know what locale they’re coming from, and you would take an NSDateFormatter, set its locale using
setLocale:, set its date and time formatting usingsetDateStyle:andsetTimeStyle:and then usedateFromString:. If you can’t do that because you don’t know the locale, then you can use the UNIX functions:Next, you want to “convert” newDate to Eastern Time. I say “convert” because NSDates don’t contain any information about timezones—they’re just represented as a number of seconds since January 1, 2001—so the idea of conversion makes no sense. When you print out an NSDate you get it in UTC (+0000), but an NSDate is no more associated with that timezone than with any other.
What you want to do instead is to create a dateFormatter with the right timezone and use it to output the date: