The easiest way to obtain the system date and time in a string is to use the following statements:
static char *z = NULL;
static struct tm *tm;
static time_t tt;
time (&tt);
tm = localtime (&tt);
z = asctime (tm);
DebugPrintf ("System time: %s\n", z);
You can paste those lines in the Interactive execution window and run them by pressing Shift-F5: the debug window will open showing this message:
System time: Wed Sep 24 10:27:03 2003
In some case I noticed in the past that this method was not up to the time zone and daylight savings time settings, so to obtain current (local) date and time, I begun to use the following SDK function:
#include
#include
static char a[50];
static SYSTEMTIME dh;
GetLocalTime(
&dh);
sprintf (a, "%d/%d/%04d %d:%02d", dh.wMonth, dh.wDay, dh.wYear, dh.wHour, dh.wMinute);
#include
DebugPrintf ("Local date and time are: %s\n", a);
Again, paste in the Interactive execution window and run. In the Debug window you will see the following message:
Local date and time are: 9/24/2003 10:33