How to change format of date/time?

Posted by 4thSpace on Stack Overflow See other posts from Stack Overflow or by 4thSpace
Published on 2010-05-20T05:19:03Z Indexed on 2010/05/20 5:20 UTC
Read the original article Hit count: 250

I have this date and time format:

2010-05-19 07:53:30

and would like to change it to:

Wednesday @ 7:53PM 5/19/2010

I'm doing this, which gets the current format:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";

but when I change the format, I end up with a null. For example:

formatter.dateFormat = @"hh:mm tt MM-dd-yyyy";
date = [formatter stringFromDate:formattedDate];

date will be null. I want to put the end result into an NSString. It would be nice if time and date could come out as separate properties so I can arrange them however I like. Any ideas on how I can change the formatting?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk