system time function?

This is a discussion on system time function? within the C Programming forums, part of the General Programming Boards category; I was wondering if there was a function to return the system time, I just wanted to make a simple ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    119

    system time function?

    I was wondering if there was a function to return the system time, I just wanted to make a simple alarm clock program that would go off at a certain time.

    Thanks,

    Ash

  2. #2
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Hi

    Do you want something like this?
    Code:
    #include <stdio.h>
    #include <time.h>
    
    int main()
    {
     time_t s;
    
     time(&s);
     printf("%s",ctime(&s));
    
     return 0;
    }
    And also, if you are using a UNIX like system (like Linux)
    using "man -K time.h" (which seraches for the manual pages including the phrase "time.h") may help you.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    119
    Thanks much!

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    119
    Also I was hoping you could tell me exactly how that works, and a way to make it so that I could make it go off at a certain time if possible. Sorry to ask, but google wasn't much help, and I didn't have much luck searching these forums either.

    Thanks,

    Ash

  5. #5
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Hi

    What i did in the above code is getting the number of elapsed seconds from 0:00:00 Jan 1, 1970 by calling time() and then storing it into s which is of type time_t.

    Then the ctime() function converts the time_t value into a human readble nice format and returns a pointer to a character string.

    As I wrote in previous message, if you are using a UNIX based system "man ctime" and "man 2 time" commands will give you much information.
    If you are not using a UNIX based system (:P), see the links below :

    http://man.linuxquestions.org/?query...ction=2&type=2
    http://man.linuxquestions.org/?query...ction=0&type=2

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    119
    Oh, ok thanks. i'm not using UNIX, just winxp

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    Time.h functions are standard, so any old manual page should be good enough for basic usage at least.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 06:11 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Passing system time to a function
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 12:56 PM

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