print the current time on the screen

  • Thread starter Thread starter Allen Maki
  • Start date Start date
A

Allen Maki

Hi everybody,



I need help.



I want to print the current time on the screen. After research I managed to
run the codes below in regular C++. But I could not make it to run in .NET
Framework environment. Can anybody tell me how to make these codes to work
in .NET Framework or show me an alternative codes?



/*

the author said that you have to turn on debug multi-threading to make this
program works

*/



#include <afx.h>

#include <iostream>

using namespace std;



int main()

{

CTime now = CTime::GetCurrentTime();

CString str = now.Format(" %H:%M:%S - ");

cout << str << endl;



return 0;

}
 
If you are using Managed C++ use this code:

System::Console::WriteLine(System::DateTime::Now->ToString("T"));

In VB and C#, use this code:

System.Console.WriteLine(System.DateTime.Now.ToString("T")); <- the
semi-colon is required for C#, but remove it for VB
 
Thanks Bryant,

I have to use ".", instead of '->'.

Like this: System::Console::WriteLine(System::DateTime::Now.ToString("T"));
 
Back
Top