Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2007

Tip: Looking for answers? Try searching our database.

print the current time on the screen

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allen Maki - 15 Apr 2007 22:04 GMT
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;

}
Peter Duniho - 15 Apr 2007 23:20 GMT
> 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?

Looks to me like the sample code you've got is written for MFC, where the  
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.