|
CTime ddate;
ddate=ddate.GetCurrentTime();
iday=ddate.GetDay();
imon=ddate.GetMonth();
iyear=ddate.GetYear();
ihrs=ddate.GetHour();
imin=ddate.GetMinute();
isec=ddate.GetSecond();
sdatef.Format("%.2d%.2d%.4d_%.2d%.2d",imon,iday,iyear,ihrs,imin,isec);
|
|
|
|
|
opps I am sorry, i did not get ur question, i belive
|
|
|
|
|
As a reply to both previous posts, Month/Day/Year is a wrong format for French so GetTimeFormat() is the right way and it does return whatever the locale has set as the format. So quite possibly the French locale has 24 hour format while Enghlish one has 12 hour AM/PM one etc. In the end, if MS was correct then whatever you get is the correct form, you don't have to get AM/PM format, it's not the only "good" one.
|
|
|
|
|
If you have your time in a COleDateTime object, you can use the Format method.
CString Format(
DWORD dwFlags = 0,
LCID lcid = LANG_USER_DEFAULT
) const;
dwFlags
Indicates one of the following locale flags:
LOCALE_NOUSEROVERRIDE Use the system default locale settings, rather than custom user settings.
VAR_TIMEVALUEONLY Ignore the date portion during parsing.
VAR_DATEVALUEONLY Ignore the time portion during parsing.
lcid
Indicates locale ID to use for the conversion.
It returns a CString with the time already formatted for you.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi,
Thanks for replying.
But the actual problem was that on french OS the regional settings for time were not set to AM/PM, that why this problem was occuring.
The problem is fixed now.
Thanks again for spending your precious time for the problem.
Purusottam Mishra
Systems Executive
|
|
|
|
|
Raj-Ekoham DwitiyoNasti wrote: But when I am running the same application(French version) on an french OS(WinXP), it is showing the time without any AM/PM marking.
What does GetLocaleInfo(LOCALE_STIMEFORMAT) return?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Can I use TextOut with possability to scroll window?
|
|
|
|
|
|
and if I use win32 without MFC?
|
|
|
|
|
The sample that led mike post will help you.
If you have an application without MFC, just remove the MFC objects in that sample and you will see the plain WIN32 functions for scrolling and text output.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
The answer is still yes but you will have to do much more work. If that is your intention I recommend you get a good book to learn fundamentals of Win32 programming from. Trying to figure it out from forums is not going to be very productive.
led mike
|
|
|
|
|
why are junk char(ýýýýÝÝÝÝÝÝÝÝÝa a Pÿ) appended while writing CString to CFile
pls advice..
|
|
|
|
|
possibly specified length of buffer is more than the string length.
post writting code.
|
|
|
|
|
Pls find the code here
strLine.Format("%s %d %d %d",strAbc,dDlgResID,dwData,nCmd);
strLine.TrimRight();
strLine=strLine+"\r\n";
CFile file;
file.Open("c:\\some.txt", CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
file.SeekToEnd();
file.Write(strLine,strLine.GetLength());
|
|
|
|
|
the first param in write() method of CFile need a pointer point to the string, but the given param is not a string , just a CString object, try LPCTSTR operation;
--i'm still alive
|
|
|
|
|
timpa_work wrote: ...try LPCTSTR operation;
That happens automatically.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This line is your problem:
ptr_Electron wrote: file.Write(strLine,strLine.GetLength());
The first character (or more) of a CString is a length byte(s). You need to get only the data:
file.Write(strline.GetBuffer(strline.GetLength(), strLine.GetLength();
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
It is not necessary to call GetBuffer() since Write() is not modifying the string.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
In this case, it is - he's using a CFile and writing a CString. Without the GetBuffer, it will write the size of the string as well as the string.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
krmed wrote: Without the GetBuffer, it will write the size of the string as well as the string.
That's what the LPCTSTR operator is for.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This not necessary, inefficient and leaks memory (where is the call to ReleaseBuffer ?).
Steve
|
|
|
|
|
There is no memory leak - nothing was allocated on the stack. As for ReleaseBuffer, it isn't needed. According to MSDN you must call ReleaseBuffer IF the data has been modified - and it hasn't.
I personally prefer the cast, but was just showing and explaining why the OP was seeing the junk.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
You haven't posted enough code to be certain but GetBuffer should be matched with a call to ReleaseBuffer . Also, as another poster pointed out, since you're not modifying the string the call is not needed; use operator LPTCSTR instead.
Steve
|
|
|
|
|
Well, the code I posted does what the OP was looking for - there isn't more code needed. He simply was writing the string to a file.
As for release buffer, MSDN says
If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CSimpleStringT member methods.
However, in his case, the contents were not changed, thus the call to ReleaseBuffer is not required.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|