How can I get the current time?

This is a discussion on How can I get the current time? within the C Programming forums, part of the General Programming Boards category; I'm looking to get the current time as an int. How can I do this?...

  1. #1
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438

    How can I get the current time?

    I'm looking to get the current time as an int. How can I do this?

  2. #2
    Registered User jawwadalam's Avatar
    Join Date
    May 2002
    Posts
    131

    Programme for Current time..

    Code:
    #include   <stdio.h>
    #include   <dos.h>
    
    int main(void)
    {
       struct  time t;
    
       gettime(&t);
       printf("The current time is: %2d:%02d:%02d.%02d\n",
              t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
       return 0;
    }
    Hope problem is solved...!
    One day you will ask what more important to you..
    I will say my life..
    and You will leave me with even knowing
    that
    You are my Life (L)

  3. #3
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Thanks a lot guys. Perfect.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Hope problem is solved...!
    That's not a portable solution though. Best stick with vVv's version, or you may end up wondering why gettime() isn't found on your compiler.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    one way is to assign the time values to ints hours, mins and secs and write macros to print them in the ways you want. You can then put this into a header file and just call your macro print_time_hms

    hth
    Monday - what a way to spend a seventh of your life

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by iain
    one way is to assign the time values to ints hours, mins and secs and write macros to print them in the ways you want. You can then put this into a header file and just call your macro print_time_hms
    ... but then if you want to do any time calculations, like mytime+300 to add 300 seconds, it becomes a bit of a chore, compared to the standard functions. I suppose it comes down to whatever the programmer wants to do with the data.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 04:41 AM
  2. Military Time Functions
    By BB18 in forum C Programming
    Replies: 6
    Last Post: 10-10-2004, 02:57 PM
  3. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 08:56 AM
  4. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 07:17 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM

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