Jonesopolis
Jonesopolis

Reputation: 25370

NSDateFormatter not getting date string parsed

This is probably obvious, but I can't seem to convert a date string into an NSDate object. Trying with:

NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"HH:mm:ss"];
NSDate *server = [df dateFromString:result];

where result is a c# datetime object converted to a string coming from a webservice. It looks like "12/14/2012 8:00:27 PM". 'server' just keeps coming up as nil.

Also, after i get it to an NSDate, i need to find the difference between 'server' and current time, in hours-minutes-seconds. Should I use NSDateComponents?

Upvotes: 0

Views: 113

Answers (1)

user529758
user529758

Reputation:

[df setDateFormat:@"HH:mm:ss"];

later

where result [...] looks like "12/14/2012 8:00:27 PM"

It certainly doesn't have the format you set, so what do you expect? You have to set the correct format in order to get this working.

Upvotes: 2

Related Questions