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

This is a discussion on Need Quick Help For Finding A Function That Finds Your Current Time On Your Computer within the C++ Programming forums, part of the General Programming Boards category; Hey guys! Just for fun, and experience, I'm trying too make a nifty, but small C++ program, which in this ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    You tried googling and missed the first result ?
    ctime (time.h) - C++ Reference
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 12: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, 09:15 PM
  4. Please help with current time in c++
    By Agnesa in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2002, 07:10 AM
  5. current time
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-21-2002, 09:48 AM

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