Thread: system time function?

  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
    275
    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
    275
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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, 03:07 AM
  2. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 07:11 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Passing system time to a function
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 01:56 PM