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 6588501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:03:22+00:00 2026-05-25T17:03:22+00:00

Would someone know why I’m experiencing weird uptime with the following method? NSProcessInfo *processInfo

  • 0

Would someone know why I’m experiencing weird uptime with the following method?

NSProcessInfo *processInfo = [NSProcessInfo processInfo];
NSTimeInterval systemUptime = [processInfo systemUptime];

For first minutes, everything seems fine, but when I come back on the app hours or days laters the uptime is still the same : 30min, or 1h34… it seems to freeze at a random moment. Mostly on iPhone 4 (rarely on Simulator or iPad)

It could be linked to my way of showing it:

+ (NSTimeInterval)uptime:(NSNumber **)days hours:(NSNumber **)hours mins:(NSNumber **)mins
{
    NSProcessInfo *processInfo = [NSProcessInfo processInfo];
        //START UPTIME///////
    NSTimeInterval systemUptime = [processInfo systemUptime];
        // Get the system calendar
    NSCalendar *sysCalendar = [NSCalendar currentCalendar];
        // Create the NSDates
    NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:(0-systemUptime)]; 
    unsigned int unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
    NSDateComponents *c = [sysCalendar components:unitFlags fromDate:date toDate:[NSDate date]  options:0]; 
        //NSString *uptimeString = [NSString stringWithFormat:@"%dd %dh %dmin", [c day],[c hour],[c minute]];
    *days = [NSNumber numberWithInt:[c day]];
    *hours = [NSNumber numberWithInt:[c hour]];
    *mins = [NSNumber numberWithInt:[c minute]];
    [date release];
        //END UPTIME////////

    return systemUptime;
}

And later in the code:

NSNumber *uptimeDays, *uptimeHours, *uptimeMins;
[CJGDevice uptime:&uptimeDays hours:&uptimeHours mins:&uptimeMins];
NSString *uptimeString = [NSString stringWithFormat:@"%@d %@h %@min",
                          [uptimeDays stringValue],
                          [uptimeHours stringValue],
                          [uptimeMins stringValue]];

EDIT: after 3 days recording the results on iPad and iPhone I can see that this uptime is wrong, the time is running too slowly, the more we wait the more it’s obvious that it’s late

  • 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-25T17:03:22+00:00Added an answer on May 25, 2026 at 5:03 pm

    This method does the trick:

    - (time_t)uptime
    {
        struct timeval boottime;
        int mib[2] = {CTL_KERN, KERN_BOOTTIME};
        size_t size = sizeof(boottime);
        time_t now;
        time_t uptime = -1;
    
        (void)time(&now);    
    
        if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) 
        {
            uptime = now - boottime.tv_sec;
        }
        return uptime;
    }
    

    Thanks to Alastair Stuart for the link.

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

Sidebar

Related Questions

I have the knowledge of C++ template, but don't know Java. Would someone explain
Does someone know a wrapper which would allow SQLite to load its data from
I am new to Python and would like to know if someone would kindly
does someone know something about TV output with dock connector. I would like to
today i would ask you if someone know how Check if the user has
Basically I would like to archive results like that: http://www.pixelapse.com/# Does someone know any
would someone please write this code: this.Loaded += (s, e) => this.loaded = true;
Would someone be able to break down the Ruby specifics of what each of
Why would someone want to use a linked-list over an array? Coding a linked-list
Why would someone use WHERE 1=1 AND <conditions> in a SQL clause (Either SQL

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.