Thread: Need Quick Help For Finding A Function That Finds Your Current Time On Your Computer

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    67

    Need Quick Help For Finding A Function That Finds Your Current Time On Your Computer

    Hey guys! Just for fun, and experience, I'm trying too make a nifty, but small C++ program, which in this case, I want the program to check the Computer's clock time and reply by what time it reads ( for ex: if it reads the clock to be after noon but before evening time, sometime before 6pm, it will reply with a cout statement saying something such as "Good afternoon!"..)

    I already have the "if" statements prepared and ect... but I HAVE NO IDEA HOW TO USE THE <time.h> HEADER FILE!!!! lol. I've tried googling and watching vids, but I haven't found anything that suits my personal needs. Can any one tell me a function in the <time.h> header file, or from ANY header file, that you think may work with what I'm aiming for. And I'm guessing if their is such a function, it would only convert the time into seconds? Which I guess would work! =)

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    You tried googling and missed the first result ?
    ctime (time.h) - C++ Reference

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    From :localtime - C++ Reference

    Code:
        /* localtime example */
    #include <stdio.h>
    #include <time.h>
    
    int main ()
    {
      time_t rawtime;
      struct tm * timeinfo;
    
      time ( &rawtime );
      timeinfo = localtime ( &rawtime );
      printf ( "Current local time and date: %s", asctime (timeinfo) );
      
      return 0;
    }

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    67
    Quote Originally Posted by manasij7479 View Post
    You tried googling and missed the first result ?
    ctime (time.h) - C++ Reference
    No, ofcourse I saw that. Actually that was the tutorial with the least amount of help. It provided the functions, but it doesn't explain how to use them. But I do appreciate your help =)

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    67
    Quote Originally Posted by DaveH View Post
    From :localtime - C++ Reference

    Code:
        /* localtime example */
    #include <stdio.h>
    #include <time.h>
    
    int main ()
    {
      time_t rawtime;
      struct tm * timeinfo;
    
      time ( &rawtime );
      timeinfo = localtime ( &rawtime );
      printf ( "Current local time and date: %s", asctime (timeinfo) );
      
      return 0;
    }

    @DaveH Thank you so much for providing me with an example program, I greatly appreciate you taking your time to do so! Can you explain to me what the many functions do, and how they work together? Such as this code fragment from the program above:
    // time ( &rawtime ); //

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You've got a list of function names and a link to the manual pages.
    Now go do some reading.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    67
    Thanks guys, appreciate all the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-21-2009, 01:02 AM
  2. Converting Zulu Time to Current Time
    By Caldus in forum C++ Programming
    Replies: 3
    Last Post: 06-08-2006, 08:54 PM
  3. Finding current path
    By eam in forum Windows Programming
    Replies: 9
    Last Post: 12-19-2003, 10:15 PM
  4. Please help with current time in c++
    By Agnesa in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2002, 08:10 AM
  5. current time
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-21-2002, 09:48 AM