The information in this article applies to:
- Microsoft Windows Software Development Kit (SDK) for Windows
versions 3.0 and 3.1
SUMMARY
The information below describes a set of functions available in the
Microsoft Software Library for formatting time and date strings using the
international settings in the Windows Control Panel.
WINTIME is a file in the Microsoft Software Library that formats time and
date strings according to the Control Panel settings.
Download WINTIME.EXE, a self-extracting file, from the Microsoft Software
Library (MSL) on the following services:
MORE INFORMATION
Windows allows the user to specify, with the Control Panel, the appropriate
format for the date and time in the user's country. The Windows API
provides no function to format strings of date and time information
according to the Control Panel's settings. The sample code module WINTIME.C
provides C source code for five functions that an application can use to
format the date and time.
WINTIME.C is designed to be as flexible and portable as possible. The
module can be used in an application or in a dynamic-link library (DLL)
without modification.
Included with the WINTIME.C file is a sample application that demonstrates
how to use the functions.
The five functions provided by WINTIME are documented below:
- LPSTR FAR PASCAL TimeGetCurDate(LPSTR lpszDate, WORD wFlags)
Description:
TimeGetCurDate() returns the current date, formatted as specified
by the user in the Control Panel.
Arguments:
Type/Name
Description
LPSTR lpszDate
Points to a buffer that is to receive the date. Must be
large enough to hold the longest date possible (64 bytes
should be large enough).
struct tm *lpTM
Pointer to a "tm" structure (from TIME.H) that contains
the time and date to be formatted.
WORD wFlags
Specifies flags that modify the behavior of the function.
May be any of the following:
Flag Meaning
---- -------
0 The date will be formatted exactly the way
Control Panel does it, using Windows's
international settings. The date will be in
the long date format (Sunday, January 1,
1991).
DATE_SHORTDATE Forces the date to be formatted using the
short date format (1/01/91).
DATE_NODAYOFWEEK The date will be formatted without the day
of week. This flag may not be used with the
DATE_SHORTDATE flag (that is, January 1,
1991).
- LPSTR FAR PASCAL TimeGetCurTime(LPSTR lpszTime, WORD wFlags)
Description:
TimeGetCurTime() returns the current time, formatted as specified
by the user in the Control Panel.
Arguments:
Type/Name
Description
LPSTR lpszTime
Points to a buffer that is to receive the formatted
time. Must be large enough to hold the longest date
possible (64 bytes should be large enough).
WORD wFlags
Specifies flags that modify the behavior of the function.
May be any of the following:
Flag Meaning
---- -------
0 The time will be formatted exactly the way
Control Panel does it, using Windows's
international settings (for example,
1:00:00 AM).
TIME_12HOUR The time will be formatted in 12 hour format
regardless of the WIN.INI international
settings. This flag may not be used with the
TIME_24HOUR flag (for example, 2:32:10 PM).
TIME_24HOUR The time will be formatted in 24 hour format
regardless of the WIN.INI international
settings. This flag may not be used with the
TIME_12HOUR flag (for example, 14:32:10).
TIME_NOSECONDS The time will be formatted without seconds
(for example, 2:32 PM).
- LPSTR FAR PASCAL TimeFormatDate(LPSTR lpszDate,
struct tm FAR *lpTM,
WORD wFlags)
Description:
TimeFormatDate() returns the date, specified in the tm structure,
formatted as specified by the user in the Control Panel.
Arguments:
Type/Name
Description
LPSTR lpszDate
Points to a buffer that is to receive the date. Must be
large enough to hold the longest date possible (64 bytes
should be large enough).
struct tm *lpTM
Pointer to a "tm" structure (from TIME.H) that contains
the time and date to be formatted.
WORD wFlags
Specifies flags that modify the behavior of the function.
May be any of the following:
Flag Meaning
---- -------
0 The date will be formatted exactly the way
Control Panel does it, using Windows's
international settings. The date will be in
the long date format (Sunday, January 1,
1991).
DATE_SHORTDATE Forces the date to be formatted using the
short date format (1/01/91).
DATE_NODAYOFWEEK The date will be formatted without the day
of week. This flag may not be used with the
DATE_SHORTDATE flag (for example, January 1,
1991).
- LPSTR FAR PASCAL TimeFormatTime(LPSTR lpszTime,
struct tm FAR *lpTM,
WORD wFlags)
Description:
Function returns the time, specified in the tm structure,
formatted as specified by the user in the Control Panel.
Arguments:
Type/Name
Description
LPSTR lpszTime
Points to a buffer that is to receive the formatted
time. Must be large enough to hold the longest date
possible (64 bytes should be large enough).
struct tm *lpTM
Pointer to a "tm" structure (from TIME.H) that contains
the time and date to be formatted.
WORD wFlags
Specifies flags that modify the behavior of the function.
May be any of the following:
Flag Meaning
---- -------
0 The time will be formatted exactly the way
Control Panel does it, using Windows's
international settings (for example,
1:00:00 AM).
TIME_12HOUR The time will be formatted in 12 hour format
regardless of the WIN.INI international
settings. This flag may not be used with the
TIME_24HOUR flag (for example, 2:32:10 PM).
TIME_24HOUR The time will be formatted in 24 hour format
regardless of the WIN.INI international
settings. This flag may not be used with the
TIME_12HOUR flag (for example, 14:32:10).
TIME_NOSECONDS The time will be formatted without seconds
(for example, 2:32 PM).
- void FAR PASCAL TimeResetInternational(void)
Description:
This function sets some local static variables to Windows's
current time and date format settings.
This function should be called every time a WM_WININICHANGE
message is sent for the [intl] section and when the DLL or
application using these functions is invoked.
These variables are in the DLL data segment. Therefore, if one
application changes this information, the others will see the
change.
|