Skovie
Skovie

Reputation: 197

NSDateFormater +0000

Hey I'm having problems formatting my date ....

my code it this :

 NSString *dateString = news.date;
 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 dateFormatter.DateFormat =@"yyyy-MM-dd'T'HH:mm:ss";

 NSDate *dateFromString = [[NSDate alloc] init];

 dateFromString = [dateFormatter dateFromString: dateString];


 NSLog(@" %@", dateFromString);

if i look at my dateString it´s 2012-03-06T12:15:45
but when i format it, it comes out 2012-03-06 11:15:45 +0000

how do i remove the +0000 ???

Upvotes: 2

Views: 3705

Answers (1)

sch
sch

Reputation: 27506

dateFromString is an NSDate instance. So 2012-03-06 11:15:45 +0000 is the correct result you get when you call NSLog(@" %@", dateFromString);. That's simply how the method description of NSDate works.

If you want to change a string of type 2012-03-06T12:15:45 to a string of type 2012-03-06 11:15:45, then you have to create another string fromdateFromString` like the following:

// ...
dateFromString = [dateFormatter dateFromString:dateString];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *newDateString = [dateFormatter stringFromDate:dateFromString];
NSLog(@"%@", newDateString);

Upvotes: 8

Related Questions