Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1032455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:04:46+00:00 2026-05-16T14:04:46+00:00

This is really strange, I’m not sure what could be causing the code to

  • 0

This is really strange, I’m not sure what could be causing the code to work perfectly half of the time and not the other half. I’m using TBXML to parse a twitter feed. I need to get the created_at date in the twitter feed which is passed like <created_at>Tue Feb 02 23:30:49 +0000 2010</created_at>. So i store these values and then pass each of them to my getTweetTime method, which will format them, get them to unix them, and then compare against the current date in order to return a string similar to twitters “about 3 hours ago” date structure.

The problem is that even though the values are all being stored correctly and passed to my getTweetTime method with the correct values, many of them don’t make it through the formatting step with a legitimate value. Heres my code:

    -(NSString *) getTweetTime:(NSString*)time
{       
    NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
    [df setDateFormat:@"ccc MMM dd hh:mm:ss Z yyyy"];
    NSDate *myDate = [df dateFromString: time];


    NSLog(@"time%@", time);
    long tweetTime =  (long)[myDate timeIntervalSince1970];
    long currentTime = (long)[[NSDate date] timeIntervalSince1970]; 

    int delta = currentTime - tweetTime;    
    NSLog(@"tweet:%ld, current:%ld", tweetTime, currentTime);

    if (delta < 60) {
        return @" (less than a minute ago)";
    } else if (delta < 120) {
        return @" (about a minute ago)";
    } else if (delta < (60 * 60)) {
        return [[NSString stringWithFormat:@" ( about %u",(delta / 60)] stringByAppendingString:@" minutes ago)"];
    } else if (delta < (120 * 60)) {
        return @" (about an hour ago)";
    } else if (delta < (24 * 60 * 60)) {        
        return [[NSString stringWithFormat:@" (about %u",((delta / 3600) - 1)] stringByAppendingString:@" hours ago)"];
    } else if (delta < (48 * 60 * 60)) {
        return @" (1 day ago)";
    } 
    else if(tweetTime == 0){return @"********";}
    else {
        return [[NSString stringWithFormat:@" (%u",(delta / 86400)] stringByAppendingString:@" days ago)"];
    }    

}

There doesn’t seem to be any pattern between whats successfully parsed each time. Here’s a typical console output of 1 success, 1 failure, where time=0 is a fail:

2010-09-02 14:45:12.963 myApp[6401:307] timeTue Aug 31 17:59:34 +0000 2010
2010-09-02 14:45:12.964 myApp[6401:307] tweet:0, current:1283463912
2010-09-02 14:45:12.970 myApp[6401:307] timeTue Aug 31 06:36:29 +0000 2010
2010-09-02 14:45:12.972 myApp[6401:307] tweet:1283236589, current:1283463912

I’ve tried adding a number of ‘Z’s to the string as well to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:04:46+00:00Added an answer on May 16, 2026 at 2:04 pm

    Try upper case HH for the hour. The standard says ‘h’ is hour from 1-12. You’ll note your example that “fails” has an hour of 17.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a really strange NPE exception. This is the offending code: private static
This is a really strange behavior, and I've set up some demo code to
This is a really strange issue. When using WebClient.DownloadFile in Debug configuration, it appears
This is really strange behavior. When I try make a search using findItemsAdvanced to
I find this really strange..could someone give an explanation? abstract class UIController{ public static
This is really strange. I have two time values. First time: $t1 = 1311165885;
This is really strange but this code is working fine unless the value entered
This is really strange. Absolute path doesn't work for both ifstream and ostream. It
I have a really strange problem with this code: In this Fiddle it alert's
This seems really strange to me: f = File.open(Dir.pwd+'/tmp','r') f.readlines do |l| puts #{f.lineno}:#{l}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.