Click to See Complete Forum and Search --> : Time/date parsing


June 22nd, 1999, 04:47 PM
Has anyone had to parse a string into a CTime? COleDateTime has a string-parsing function, but I'd rather not involve any OLE functions since my program doesn't need to (the function calls a Var... function).
It doesn't look easy because I want to parse dates/times according to the user's locale, rather than the American format (I am English so I'm pedantic about these things...)
Does anyone have any ready-made code they'd like to share? Or is there a way of extracting the date/time format from the system, in a form that can be used by a parsing function.
Any help appreciated.

Tim Robinson: asantana@acutrak.demon.co.uk

Victor C
June 22nd, 1999, 05:31 PM
Hi,
Greets. It really depends on what type of input string you want to parse.

e.g if you have string that has some predefined date time values in it... like

06/22/1999 12:30:10 (June 22 1999 12:30:10) you might want to do a sscanf

<code>
void main()
{
const char* pszDateTime = "06/22/1999 12:30:10";
short nMonth = 0, nDate = 0, nYear = 0, nHour = 0, nMin = 0, nSec = 0;
sscanf(pszDateTime, TEXT("%02d/%02d%04d %02d:%02d:%02d"), &nMonth, &nDate, &nYear, &nHour, &nMin, &nSec);
CTime MyTime(nYear, nMonth, nDate, nHour, nMin, nSec);
}
</code>
Go merry with the new MyTime object.....
Hope this helps....good luck

Victor.C