iPhone + Twitter API: Converting time?

后端 未结 4 928
旧时难觅i
旧时难觅i 2020-12-30 09:14

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

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 09:42

    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];
    

提交回复
热议问题