15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Displaying Time/Date in current locale

Ronen Lamdan -- ronenl@netmanage.co.il
Thursday, September 19, 1996

Environment: VC++ 4.0 and 1.52, Win 95/NT and 3.11

I would like to display a time/date string according to the international time/date
settings on the current machine.  For example, in the US I would display:
	9/19/96 8:26 pm
and in Europe:
	19/9/96 20:26
or however the user set up his control panel.  So how do I get the display format
in 16-bits?  In 32-bits it's easy, just use GetDateFormat/GetTimeFormat as below.
Is there a solution that would work equally well in 16 AND 32-bits?

	CString timeString;
 	CTime* t = GetDate();

	char buf[50];
	SYSTEMTIME systime;
	systime.wYear         = (WORD)t->GetYear();
	systime.wMonth        = (WORD)t->GetMonth();
	systime.wDayOfWeek    = (WORD)t->GetDayOfWeek() - 1;// 0-index Vs. 1-index
	systime.wDay          = (WORD)t->GetDay();
	systime.wHour         = (WORD)t->GetHour();
	systime.wMinute       = (WORD)t->GetMinute();
	systime.wSecond       = (WORD)t->GetSecond();
	systime.wMilliseconds = 0;
	
	if (GetDateFormat(NULL, DATE_SHORTDATE, &systime, NULL, buf, sizeof(buf)))
	{
		timeString = CString(buf);
		if (GetTimeFormat(NULL, TIME_NOSECONDS, &systime, NULL, buf, 20))
			timeString += CString(" ") + CString(buf);
	}



                                                             _ o 
                                                              /\  \__/ 
*******[Home of Chameleon - TCP/IP Applications for Windows] | \  / /o
* Name: Ronen Lamdan                                               *
*                                                                  *
* NetManage Ltd, Jerusalem        | E-mail: ronenl@netmanage.co.il * \ /
* Industrial Park Mevasseret Zion | Voice : +972-2-344052          *  |
* Mevasseret Zion, Israel   90805 | FAX   : +972-2-344058          * /o\
*                                                                  *
*       Flying saucers are real, the Air Force doesn't exist.      *
*                                                                  *
**************************************************oOOo*( )*oOOo*****
                                                      (o o)
                                                      //|\\




Mike Blaszczak -- mikeblas@nwlink.com
Sunday, September 22, 1996

[Mini-digest: 3 responses]

At 09:24 PM 9/19/96, you wrote:
>Environment: VC++ 4.0 and 1.52, Win 95/NT and 3.11

>I would like to display a time/date string according to the international
time/date
>settings on the current machine.  For example, in the US I would display:
>	9/19/96 8:26 pm
>and in Europe:
>	19/9/96 20:26
>or however the user set up his control panel.  So how do I get the display
format
>in 16-bits?  In 32-bits it's easy, just use GetDateFormat/GetTimeFormat as
below.
>Is there a solution that would work equally well in 16 AND 32-bits?

There's certainly such a solution, but you'll have to write it yourself or find
it from a third party.  Win16 doesn't support locales very strongly, while Win32
does.  In Win16, you'll need to get the date and time format rules that the user
has set up in Control Panel.  That information is available in SYSTEM.INI, if I
remember correctly--it might be in WIN.INI.

After that, you'll need to parse the string description of what the user
wants and
write your own formatting routine.

Neither MFC, Win16, nor the CRTL provide support for this.  You might be able to
use the same support from OLE automation that MFC uses under Win32--I really 
can't remmeber if that support is provided by 16-bit OLE.  Have a look at the
implementation of the MFC 4.x class COleDateTime() to get a starting point.

.B ekiM
http://www.nwlink.com/~mikeblas/
Don't look at my hands: look at my _shoulders_!
These words are my own. I do not speak on behalf of Microsoft.

-----From: Tomas Gudmundsson 

Hi !
his is easy, use the Format() function in COleDateTime !
  Tomas Gudmundsson, Danish Hydraulic Institute

-----From: David.Lowndes@bj.co.uk

Ronen,

I'm not aware of any specific Win16 facility to do this for you, but you could write
your own wrapper to hide differences between the platforms and get the relevant
information from the win.ini [Intl] section.

You can use GetProfileInt/String to retreive the iTime, sTime, s1159, s2359,
sShortDate etc. settings and format the result yourself.

Dave Lowndes



Gabriel Parlea-Visalon -- Gabriel@derivs.demon.co.uk
Monday, September 23, 1996

[Mini-digest: 2 responses]

In WIN.INI, the Intl section you can find the entries you need. It doesn't 
matter if the system is a 16 or 32 bit one.

Gabriel

> Environment: VC++ 4.0 and 1.52, Win 95/NT and 3.11
> 
> I would like to display a time/date string according to the international 
time/date
> settings on the current machine.  For example, in the US I would display:
> 	9/19/96 8:26 pm
> and in Europe:
> 	19/9/96 20:26
> or however the user set up his control panel.  So how do I get the display 
format
> in 16-bits?  In 32-bits it's easy, just use GetDateFormat/GetTimeFormat as 
below.
> Is there a solution that would work equally well in 16 AND 32-bits?
> 
> 	CString timeString;
>  	CTime* t = GetDate();
> 
> 	char buf[50];
> 	SYSTEMTIME systime;
> 	systime.wYear         = (WORD)t->GetYear();
> 	systime.wMonth        = (WORD)t->GetMonth();
> 	systime.wDayOfWeek    = (WORD)t->GetDayOfWeek() - 1;// 0-index Vs. 
1-index
> 	systime.wDay          = (WORD)t->GetDay();
> 	systime.wHour         = (WORD)t->GetHour();
> 	systime.wMinute       = (WORD)t->GetMinute();
> 	systime.wSecond       = (WORD)t->GetSecond();
> 	systime.wMilliseconds = 0;
> 	
> 	if (GetDateFormat(NULL, DATE_SHORTDATE, &systime, NULL, buf, 
sizeof(buf)))
> 	{
> 		timeString = CString(buf);
> 		if (GetTimeFormat(NULL, TIME_NOSECONDS, &systime, NULL, buf, 
20))
> 			timeString += CString(" ") + CString(buf);
> 	}
> 
> 
> 
>                                                              _ o 
>                                                               /\  \__/ 
> *******[Home of Chameleon - TCP/IP Applications for Windows] | \  / /o
> * Name: Ronen Lamdan                                               *
> *                                                                  *
> * NetManage Ltd, Jerusalem        | E-mail: ronenl@netmanage.co.il * \ /
> * Industrial Park Mevasseret Zion | Voice : +972-2-344052          *  |
> * Mevasseret Zion, Israel   90805 | FAX   : +972-2-344058          * /o\
> *                                                                  *
> *       Flying saucers are real, the Air Force doesn't exist.      *
> *                                                                  *
> **************************************************oOOo*( )*oOOo*****
>                                                       (o o)
>                                                       //|\\
> 
> 

-- 
                             Gabriel Parlea-Visalon
                               Software Engineer
                           Derivative Trading Systems
                           gabriel@derivs.demon.co.uk

-----From: Andrew Gebbie 

Hi Ronen

I have this problem as well in 16 bit Windows, so if you hear of a
solution I'd be grateful to know about it.  The root problem here is
that the 16-bit runtime stuff only supports the "C" locale, and so
strftime() etc can't do any others.

Andrew



Jeremy Smith -- jeremy_smith@mentec.ie
Wednesday, September 25, 1996

[Mini-digest: 3 responses]

Folks,

May I suggest ftp.microsoft.com/Softlib/MSLFILES/WINTIME.EXE - a self extracting
file with everything you need and it works.



______________________________ Reply Separator _________________________________
Subject: Re: Displaying Time/Date in current locale
Author:  mfc-l@netcom.com at internet-mail
Date:    24/09/96 21:14


[Mini-digest: 2 responses]

In WIN.INI, the Intl section you can find the entries you need. It doesn't 
matter if the system is a 16 or 32 bit one.

Gabriel

> Environment: VC++ 4.0 and 1.52, Win 95/NT and 3.11 
> 
> I would like to display a time/date string according to the international 
time/date
> settings on the current machine.  For example, in the US I would display: 
>  9/19/96 8:26 pm
> and in Europe:
>  19/9/96 20:26
> or however the user set up his control panel.  So how do I get the display 
format
> in 16-bits?  In 32-bits it's easy, just use GetDateFormat/GetTimeFormat as 
below.
> Is there a solution that would work equally well in 16 AND 32-bits? 
> 
>  CString timeString;
>   CTime* t = GetDate();
> 
>  char buf[50];
>  SYSTEMTIME systime;
>  systime.wYear         = (WORD)t->GetYear(); 
>  systime.wMonth        = (WORD)t->GetMonth();
>  systime.wDayOfWeek    = (WORD)t->GetDayOfWeek() - 1;// 0-index Vs. 
1-index
>  systime.wDay          = (WORD)t->GetDay(); 
>  systime.wHour         = (WORD)t->GetHour();
>  systime.wMinute       = (WORD)t->GetMinute(); 
>  systime.wSecond       = (WORD)t->GetSecond(); 
>  systime.wMilliseconds = 0;
>  
>  if (GetDateFormat(NULL, DATE_SHORTDATE, &systime, NULL, buf, 
sizeof(buf)))
>  {
>   timeString = CString(buf);
>   if (GetTimeFormat(NULL, TIME_NOSECONDS, &systime, NULL, buf, 
20))
>    timeString += CString(" ") + CString(buf); 
>  }
> 
> 
> 
>                                                              _ o 
>                                                               /\  \__/ 
> *******[Home of Chameleon - TCP/IP Applications for Windows] | \  / /o 
> * Name: Ronen Lamdan                                               *
> *                                                                  *
> * NetManage Ltd, Jerusalem        | E-mail: ronenl@netmanage.co.il * \ / 
> * Industrial Park Mevasseret Zion | Voice : +972-2-344052          *  | 
> * Mevasseret Zion, Israel   90805 | FAX   : +972-2-344058          * /o\ 
> *                                                                  *
> *       Flying saucers are real, the Air Force doesn't exist.      * 
> *                                                                  * 
> **************************************************oOOo*( )*oOOo***** 
>                                                       (o o)
>                                                       //|\\ 
> 
> 

-- 
                             Gabriel Parlea-Visalon
                               Software Engineer
                           Derivative Trading Systems
                           gabriel@derivs.demon.co.uk

-----From: "Brian V. Zaino (516) 434-6278" 

If you would like some sample 16 bit "c" code that does it, check out
Microsoft's sample program WINTIME.EXE.  It should be available as a
self-extracting file from the Microsoft Software Library (MSL) on the
following services:
 
 - Microsoft Download Service (MSDL)
      Dial (206) 936-6735 to connect to MSDL
      Download WINTIME.EXE
 
 - Internet (anonymous FTP)
      ftp ftp.microsoft.com
      Change to the \SOFTLIB\MSLFILES directory
      Get WINTIME.EXE


Brian

-----From: pjn@indigo.ie (pjn)


I afraid you will have to understand and parse the contents of the
win.ini file. There was an article in an MSDN article from a number of
years back. You might also want to have a look at a number of classes
i have developed for handing date and times. Its home page is
http://indigo.ie/~pjn/dtime.html.


                             '''	   
                             @ @
+========================ooO-(_)-Ooo=================================+
|                                           PJ Naughter              |
|                                                                    |
| Software Developer                   Email: pjn@indigo.ie          |
| Softech Telecom                      Tel:   +353-1-2958384         |
|                                      Fax:   +353-1-2956290         |
| Author of DTime - A Collection       URL:   http://indigo.ie/~pjn  |
| of Date & Time classes for MFC                                     |
|                                                                    |
|                  Addr: 7 Woodford, Brewery Road, Stillorgan,       |
|                        Blackrock, Co. Dublin, Republic of Ireland  |
+====================================================================+



John -- John.Weeder@abii.com
Friday, September 27, 1996

[Mini-digest: 2 responses]

WINTIME is a nice; but here is a little more quick & dirty method using
OLE variants and MFC...

CString InternationalDateTimeString(int iYear,int iMonth,int iDay,int
iHour,int iMinute,int iSecond)
{
	try 
	{
		COleVariant
varDt(COleDateTime(iYear,iMonth,iDay,iHour,iMinute,iSecond));
		varDt.ChangeType(VT_BSTR);
		return CString(V_BSTR(&varDt));
	}
	catch (CException* e)
	{
		e->ReportError();
		e->Delete();
	}
	return CString("...default...");
}
...
	CString string = InternationalDateTimeString(1999, 1, 25, 23, 45, 58);
...

>----------
>From: 	Jeremy Smith
>Sent: 	Wednesday, September 25, 1996 5:08 AM
>To: 	mfc-l@netcom.com
>Subject: 	Re[2]: Displaying Time/Date in current locale
>
>[Mini-digest: 3 responses]
>
>Folks,
>
>May I suggest ftp.microsoft.com/Softlib/MSLFILES/WINTIME.EXE - a self
>extracting
>file with everything you need and it works.
>
>
>
>______________________________ Reply Separator
>_________________________________
>Subject: Re: Displaying Time/Date in current locale
>Author:  mfc-l@netcom.com at internet-mail
>Date:    24/09/96 21:14
>
>
>[Mini-digest: 2 responses]
>
>In WIN.INI, the Intl section you can find the entries you need. It
>doesn't 
>matter if the system is a 16 or 32 bit one.
>
>Gabriel
>
>> Environment: VC++ 4.0 and 1.52, Win 95/NT and 3.11 
>> 
>> I would like to display a time/date string according to the international 
>time/date
>> settings on the current machine.  For example, in the US I would display: 
>>  9/19/96 8:26 pm
>> and in Europe:
>>  19/9/96 20:26
>> or however the user set up his control panel.  So how do I get the display 
>format
>> in 16-bits?  In 32-bits it's easy, just use GetDateFormat/GetTimeFormat as 
>below.
>> Is there a solution that would work equally well in 16 AND 32-bits? 
>> 
>>  CString timeString;
>>   CTime* t = GetDate();
>> 
>>  char buf[50];
>>  SYSTEMTIME systime;
>>  systime.wYear         = (WORD)t->GetYear(); 
>>  systime.wMonth        = (WORD)t->GetMonth();
>>  systime.wDayOfWeek    = (WORD)t->GetDayOfWeek() - 1;// 0-index Vs. 
>1-index
>>  systime.wDay          = (WORD)t->GetDay(); 
>>  systime.wHour         = (WORD)t->GetHour();
>>  systime.wMinute       = (WORD)t->GetMinute(); 
>>  systime.wSecond       = (WORD)t->GetSecond(); 
>>  systime.wMilliseconds = 0;
>>  
>>  if (GetDateFormat(NULL, DATE_SHORTDATE, &systime, NULL, buf, 
>sizeof(buf)))
>>  {
>>   timeString = CString(buf);
>>   if (GetTimeFormat(NULL, TIME_NOSECONDS, &systime, NULL, buf, 
>20))
>>    timeString += CString(" ") + CString(buf); 
>>  }
>> 
>> 
>> 
>>                                                              _ o 
>>                                                               /\  \__/ 
>> *******[Home of Chameleon - TCP/IP Applications for Windows] | \  / /o 
>> * Name: Ronen Lamdan                                               *
>> *                                                                  *
>> * NetManage Ltd, Jerusalem        | E-mail: ronenl@netmanage.co.il * \ / 
>> * Industrial Park Mevasseret Zion | Voice : +972-2-344052          *  | 
>> * Mevasseret Zion, Israel   90805 | FAX   : +972-2-344058          * /o\ 
>> *                                                                  *
>> *       Flying saucers are real, the Air Force doesn't exist.      * 
>> *                                                                  * 
>> **************************************************oOOo*( )*oOOo***** 
>>                                                       (o o)
>>                                                       //|\\ 
>> 
>> 
>
>-- 
>                             Gabriel Parlea-Visalon
>                               Software Engineer
>                           Derivative Trading Systems
>                           gabriel@derivs.demon.co.uk
>
>-----From: "Brian V. Zaino (516) 434-6278" 
>
>If you would like some sample 16 bit "c" code that does it, check out
>Microsoft's sample program WINTIME.EXE.  It should be available as a
>self-extracting file from the Microsoft Software Library (MSL) on the
>following services:
> 
> - Microsoft Download Service (MSDL)
>      Dial (206) 936-6735 to connect to MSDL
>      Download WINTIME.EXE
> 
> - Internet (anonymous FTP)
>      ftp ftp.microsoft.com
>      Change to the \SOFTLIB\MSLFILES directory
>      Get WINTIME.EXE
>
>
>Brian
>
>-----From: pjn@indigo.ie (pjn)
>
>
>I afraid you will have to understand and parse the contents of the
>win.ini file. There was an article in an MSDN article from a number of
>years back. You might also want to have a look at a number of classes
>i have developed for handing date and times. Its home page is
>http://indigo.ie/~pjn/dtime.html.
>
>
>                             '''	   
>                             @ @
>+========================ooO-(_)-Ooo=================================+
>|                                           PJ Naughter              |
>|                                                                    |
>| Software Developer                   Email: pjn@indigo.ie          |
>| Softech Telecom                      Tel:   +353-1-2958384         |
>|                                      Fax:   +353-1-2956290         |
>| Author of DTime - A Collection       URL:   http://indigo.ie/~pjn  |
>| of Date & Time classes for MFC                                     |
>|                                                                    |
>|                  Addr: 7 Woodford, Brewery Road, Stillorgan,       |
>|                        Blackrock, Co. Dublin, Republic of Ireland  |
>+====================================================================+
>
-----From: Andrew Gebbie 

Hi

> May I suggest ftp.microsoft.com/Softlib/MSLFILES/WINTIME.EXE - a self
extracting
> file with everything you need and it works.

I too have the 16-bit date/time display problem, and I tried WinTime
quickly this morning.  It works under Western Windows, but not at all
well in Eastern (DBCS) versions.  I've not looked into it much, but I
didn't see a lot of use of AnsiNext, so I guess they didn't even try. 
Also, it gets the day and month texts from the application rather than
from Windows, which is a shame, given that the control panel can
obviously manage it.

A good starting point, though.

Andrew Gebbie





| Вернуться в корень Архива |