Is there an easy way to convert the time stamp you get from twitter into unix time or minutes since now? I could parse through the string and convert everything myself but I'm hoping there is a way to convert that doesn't need that. Here is an example of a created_at element with a time stamp.
Sun Mar 18 06:42:26 +0000 2007
You can use NSDateFormatter with something like this :
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocale];
[usLocale release];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
// see http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
[dateFormatter setDateFormat: @"EEE MMM dd HH:mm:ss Z yyyy"];
NSDate *date = [dateFormatter dateFromString:[currentDict objectForKey:@"created_at"]];
[dateFormatter release];
NSTimeInterval seconds = [date timeIntervalSince1970];
I have been strugeling with this all day, but this thread helped me to find a solution.
This is how I convert the Twitter "created_at" attribute to a NSDATE;
NSDateFormatter *fromTwitter = [[NSDateFormatter alloc] init];
// here we set the DateFormat - note the quotes around +0000
[fromTwitter setDateFormat:@"EEE MMM dd HH:mm:ss '+0000' yyyy"];
// We need to set the locale to english - since the day- and month-names are in english
[fromTwitter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-US"]];
NSString *dateString = [item objectForKey:@"created_at"];
NSDate *tweetedDate = [fromTwitter dateFromString:dateString];
I hope someone will find this helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With