Hi,
How do I display the system's date and time in real time on a console application? Thanks.
Hi,
How do I display the system's date and time in real time on a console application? Thanks.
much like my ex, this is the quick, cheap, and dirty method:
date and time are basic dos commands if that is what you are looking for
Code:system("date"); //you'll have to make a provision for //when the date command prompts you for a //new date
Last edited by The Brain; 03-19-2005 at 07:45 AM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
I think I need more help...here's what I want to do: I need to create a file on the first second of every new day. I know my program will have to be running all the time and that's not a problem, but I have no idea how to do what I want. Any suggestions?
Use the task scheduler provided by your platform. For Windows, this can be found under Start Menu->Programs->Accessories->System Tools->Scheduled Tasks.
There is a really easy way of doing it, but it isn't the best. On the other hand, there is another way with Win32, but I'm not too sure bout that, so I'll post the other other way for now
The first way is to do something like this...
This method works, but you need to start it off at midnight for it to work the way it should. Also, include the windows header file to use the Sleep function.Code:#include <fstream> while(1) { Sleep( 86400000 ); // This is the millisecond equivilant of 24 hours ofstream a_file ( "File.txt" ); std::a_file << "This will be in the file 'File.txt'."; a_file.close(); }
Last edited by Finchie_88; 03-19-2005 at 11:27 AM.
Code:#include <ctime> char *str; time_t cur_time = time(NULL); //cur_time should be your calaender time (in seconds) from: strftime(str, 128, "%A %d %B %H %Y", 0); printf("%s", str);