Thread: Need some help with fetching the time.

  1. #1
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259

    Need some help with fetching the time.

    okey what I need help with is taking the time and putting it in a variabel so that I can use it to play around with so far I´ve read a ton of manuals but none tells me how to do it. So far I have figurd out that I should use ctime time or localtime along with tm_sec or tm_min (and so on) so um how do I take the clocks time and add it to a variabel so that I can count with it ( I only want a part of the time like seconds for instans)

    (hope this is readabel I´ve goten much complants on using "bad" and "unreadabel" english.)
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Maybe something like this:
    Code:
    #include <stdio.h>
    #include <time.h>
    
    int main(void)
    {
      time_t tim = time(NULL);
      int ch;
      
      puts ("Press Enter to increment the time, q to quit");
      do
      {
        printf("Virtual time now: %s", ctime(&tim));
        tim += 1;
      } while ((ch = getchar()) != EOF && ch != 'q');
      
      return 0;
    }
    If you want to format the time output, check out strftime().
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    but your code doesn´t anser my question that only tells me how to print out the time witch I alrady know my question is how do I get JUST the SECONDS ? but thx for your help anyway
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Shogun
    but your code doesn´t anser my question that only tells me how to print out the time witch I alrady know my question is how do I get JUST the SECONDS ? but thx for your help anyway
    Then you need to reread my post more carefully, the answers are there.
    Code:
    #include <stdio.h>
    #include <time.h>
    
    int main(void)
    {
      time_t tim = time(NULL);
      char buf[BUFSIZ];
      strftime(buf, sizeof buf, "%S", localtime(&tim));
      puts(buf);
      return 0;
    }
    If this isn't what you want, be more specific.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    I think thats exactly what I whant (thx a ton man (do you know for how long I`ve been looking for this ? ) if I use it the way I think I do I`m gonna rock at this
    Last edited by Shogun; 03-20-2003 at 08:56 AM.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  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, 06:17 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM