|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
print the current time on the screenI 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; } On Sun, 15 Apr 2007 14:04:27 -0700, Allen Maki <allenm***@sbcglobal.net>
wrote: > I want to print the current time on the screen. After research I Looks to me like the sample code you've got is written for MFC, where the > 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? CTime class provides the functionality you seek. In .NET Framework, you should look at the DateTime class for the same functionality. DateTime.Now will get you the current time, and you can use Console.WriteLine() to print out a given DateTime instance. For example: Console.WriteLine(DateTime.Now.ToString()); That will use the default formatting for the time. You can use different formatting options to get the string output in a particular format. Hope that helps. Pete |
|||||||||||||||||||||||