System Uptime

This is a discussion on System Uptime within the Windows Programming forums, part of the Platform Specific Boards category; I've been looking around and have searched these forums for a way of getting the system uptime but could'nt find ...

  1. #1
    kolt554
    Guest

    System Uptime

    I've been looking around and have searched these forums for a way of getting the system uptime but could'nt find anything. If you can help, please do, thanks.

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Look into GetTickCount().
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    kolt554
    Guest
    GetTickCount() returns time since Windows started in milliseconds. But what I've written is'nt very good:
    Code:
    DWORD ms = GetTickCount();
    DWORD secs, mins, hours, days;
    
    secs=ms/1000;
    mins=secs/60;
    hours=mins/60;
    days=hours/24;
    Gives me this:
    Milliseconds: 188299656
    Seconds: 188299
    Minutes: 3138
    Hours: 52
    Days: 2
    Which is not what I want. I want to end up with something which outputs something like "2 days, 4 hrs, 38 mins" - please help! Thanks.

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    just a little bit of extra math chief. I'll give you a hint. what's the number of hours when you subtract (days * 24) from it?
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Look up the floor function in math.h/cmath. After that, you are going to want to start with the greatest one (days) and work your way down. Every time you take a value, subtract the number of milliseconds from the total.

  6. #6
    kolt554
    Guest
    o k i c.

    But it seems I can't think, it's all null. Like, with your help, I came up with:

    hours-days*24

    to give me the hours i was after. But how do i get the minutes? Thanks

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    days=miliseconds/(1000*60*60*24);
    miliseconds-=days*1000*60*60*24;
    //do the rest the same way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 12:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 06:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 04:35 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21