how can i convert DateTime value to string in C++
//this is my demo program
using namespace System;
using namespace System::IO;
void main()
{
DateTime dt = Directory::GetLastWriteTime( "C:\\debug.log" );
//char str[] = (char)dt;
string strTemp;
}
i want to convert the dt value to a string,
i tried converting to char array it failed.
pls do help me.
Thanks in Advance
Re: how can i convert DateTime value to string in C++
No, No, No...
Do you even realized what you commented out does?
[CODE]
char str[] = (char)dt;
[\CODE]
(char)dt is a single character, being the first character in the dt string.
On second thought, I don't even think it does that.
You see, DateTime is an entire structure.
Typecasting to a char will just take the most significant byte of the entire structure.
Look up the structure if you don't believe me.
Of course, that doesn't do what you want.
use the ToString method like this:
[CODE]
std::string str = dt.ToString();
[\CODE]
Remember this is a C++ string, so you must #include <string>
Print it out with cout