time

This is a discussion on time within the C++ Programming forums, part of the General Programming Boards category; How to make a programm to display the current time on the command prompt how to read the time from ...

  1. #1
    Performer
    Join Date
    Jan 2007
    Location
    Macedonia
    Posts
    54

    Question time

    How to make a programm to display the current time on the command prompt
    how to read the time from the system clock
    i know i have to include time.h but i don't know the function's to do it

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,746
    There's what - a dozen functions in time.h tops?

    Maybe read the manual page for each one and then think about which can be used to solve the problem.

    Several can be used in several ways, but that's beside the point.
    You need to do some research of your own and come up with an attempt.
    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.

  3. #3
    Performer
    Join Date
    Jan 2007
    Location
    Macedonia
    Posts
    54
    Code:
    time_t time(time_t* timer)
    Get the current time from the system clock. Stores that value in timer. If timer is null, the value is not stored, but it is still returned by the function
    i read this on my tutorial but there isn't any tutorial to teach me how to use this function to display the time on the screen
    Last edited by Dave_Sinkula; 04-14-2007 at 03:24 PM. Reason: Code tags are spelled [code][/code] -- not [tag][/tag].

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    if Windows;

    Code:
         #include <windows.h>
         #include <iostream>
     
         int main()
         {
             SYSTEMTIME date, time;
         
                 GetLocalTime(&date);
                 GetLocalTime(&time);
             
                     int a=time.wSecond;
                     int b=time.wMinute;
                     int c=time.wHour;
            
             int x=date.wMonth;
             int y=date.wDay;
             int z=date.wYear;
             
     std::cout<<x<<"-"<<y<<"-"<<z<<" is the date"<<std::endl;
     std::cout<<a<<":"<<b<<":"<<c<<" is the time"<<std::endl;
     
     std::cin.get();
         }

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,746
    Well look at other functions which take either a time_t or a time_t* parameter and see if they get you closer to your goal.
    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
    Performer
    Join Date
    Jan 2007
    Location
    Macedonia
    Posts
    54
    strftime(buf, sizeof(buf), "&#37;a %Y-%m-%d %H:%M:%S %Z", &ts);
    i have this part of code where buf is char of 50 characters and ts is tm structure i dont know how strftime place the current time in buf

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    So go research strftime().

    You'd think the forums are an interactive dictionary. We're not all librarians, paid to do your research for you.

    http://www.google.com/search?hl=en&q...=Google+Search

    Oh, look. The second entry on google deals with C/C++.

    http://opengroup.org/onlinepubs/0079.../strftime.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 03:03 AM
  2. Replies: 11
    Last Post: 03-29-2009, 01:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM

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