HOWTO: Setting the System Date and Time Programmatically (188897)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 5.0
- Microsoft Visual FoxPro for Windows 5.0a
This article was previously published under Q188897 SUMMARY
Although the system date and time can be set manually from Control Panel,
programatically changing these settings requires using the Win32
SetLocalTime function.
SetLocalTime is passed a SYSTEMTIME structure, containing the following
members:
WORD wYear
WORD wMonth
WORD wDayOfWeek
WORD wDay
WORD wHour
WORD wMinute
WORD wSecond
WORD wMilliseconds
Similar to all structures, you must construct a string containing its
proper memory representation. The Word2Str function in the code below
performs this conversion.
Also, note that it is necessary to subtract 1 from the result of the FoxPro
dow() function to obtain the wDayOfWeek member. Win32 treats Sunday as day
0 (zero) and Saturday as day 6, whereas dow() treats Sunday as day 1 and
Saturday as day 7.
It is more convenient to use the SetLocalTime function rather than the
intuitively more obvious choice, SetSystemTime, because the former treats
the SYSTEMTIME structure as a timezone-adjusted local time, while the
latter function treats the SYSTEMTIME structure as Greenwich Mean Time.
REFERENCES
The Win32 API help file included in the MSDN Platform SDK CD.
Modification Type: | Major | Last Reviewed: | 7/30/1999 |
---|
Keywords: | kbhowto KB188897 |
---|
|