Hi,
How do I display the system's date and time in real time on a console application? Thanks.
Printable View
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
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 :D
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();
}
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);