On 1 Jul 2008, at 18:20, [EMAIL PROTECTED] wrote:


Hello,

I have a date event returned as a date time string from a feed in the
following format,

"Tue 01 Jul 2008 15:00:00 +0100"

I'm assuming this is GMT plus one hour, I'd like to convert this string to
the to a more user friendly date time string such as,

"Today at 9:00am" or "Tue Jul 01, 2008 9:00am"

that would take into account the current Time Zone setting of the Mac
displaying the date event.  I've looked at the NSDateFormatter and
NSCalendarDate, but didn't see anything that takes into account the Time Zone setting on the current Mac. Does anyone know of where I might find or
have a sample of a code snippet that does something similar to this?


So there are two parts to your problem. First you need to take the original string and create an NSDate object from it. To do this, create an NSDateFormatter and set up its -dateFormat property to match the "Tue 01 Jul 2008 15:00:00 +0100" format. This link may be handy for formatting info:

file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html #//apple_ref/doc/uid/TP40002369-DontLinkElementID_13

Now that you have a NSDate object, you'll want a second NSDateFormatter that converts the date into the desired string format. For the most part, you can achieve the "Tue Jul 01, 2008 9:00am" style dates with -setDateStyle: and -setTimeStyle: I would STRONGLY recommend you use this rather than try to specify your own date format string as it means dates will match the user's preferences.

You can then subclass NSDateFormatter to supplement the behaviour to generate "Today" etc. when appropriate. For all I know, there may exist a 3rd party NSDateFormatter subclass to do this already.

Mike.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to