I’m developing an application and I need to parse a Tweet timestamp that actually is a string like this:
“Mon, 17 Oct 2011 10:20:40 +0000”
However what I need it is only the time. So what I’m trying to get it is:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
NSDate *date = [dateFormatter dateFromString:timestamp];
but when I try to print the Date with NSLog the output is (null) and I don’t understand why. What I need, if it is possible, is to create a date object only with the time. Indeed later on I need to compare different dates but I care only about the time. It is not important if the date are different because of the day, month or year, the important is that I can compare them with the “timeIntervalSinceDate” to get the difference in seconds.
Any help will be really appreciated.
Thanks
Ale
NSDATEis al full date object, it needs a date en time.You can use
NSDateFormatterto only display the time, but you will need to parse the full string to get theNSDateobject.Here some code you can use:
You need to set the local to make sure it read the timestamp in the correct language.
Also alloced the dateFormatter outside any loops and release it after you’re done with the loop.