954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Clock in Windows Forms

Hi,
I am able to create a clock in a console c++ app...like this one show UTC hours:

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <stdio.h>

void main()
{
    SYSTEMTIME st, lt;
    
    GetSystemTime(&st);
    GetLocalTime(&lt);
    
	std::cout << st.wHour << std::endl;
	std::cin.get();
}


But I am not able to create this with the .NET Framework 3.5, I mean Windows Forms.
I want to assign HOURS : MINUTES : SECONDS to a label.
Can you help me out?


Regards

electrox73
Newbie Poster
12 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

Look into a DateTime object: http://msdn.microsoft.com/en-us/library/system.datetime_members(v=VS.90).aspx

Create an instance of a DateTime object and set it equal to DateTime::Now, then just use the hours, minutes, seconds members to get what you need.

If you want it to update every second, use a Timer object.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

Look into a DateTime object: http://msdn.microsoft.com/en-us/library/system.datetime_members(v=VS.90).aspx

Create an instance of a DateTime object and set it equal to DateTime::Now, then just use the hours, minutes, seconds members to get what you need.

If you want it to update every second, use a Timer object.

Sorry, but that's kinda too complicated to me, isn't there an easier way?


Regards

electrox73
Newbie Poster
12 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

That's actually probably the least complicated way. What problems are you having in implementing it?

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: