Click here to Skip to main content
15,904,503 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi how can i use datetimepicker on C# for display every seconds of time on project like date and of PC that changes every seconds?
Posted
Comments
mohsenvasefi 16-Nov-13 9:47am    
and counts intervally

A DateTimePicker isn't meant for display of date and time - it's meant for the user to enter information.

If you want to display the current date and time so that it changes every second:
0) Add a Label to your form
1) Add a Timer to your form.
2) Set it's Interval property to 500 - that's every half a second.
3) Set up a handler for its Tick event
4) In the handler, set the Label.Text property to the current time:
C#
myLabel.Text = DateTime.Now.ToString();
 
Share this answer
 
Comments
mohsenvasefi 16-Nov-13 10:15am    
thank you
i've done by another method! look to up please and tell me it's right or not
Yücel Güven 16-Nov-13 10:16am    
Just as an addition to OriginalGriff's solution, you can also change the time format with:
myLabel.Text = DateTime.Now.ToString("HH:mm:ss.fff");
mohsenvasefi 16-Nov-13 10:21am    
and how can i change 6:53:23PM to 18:53:23?
Yücel Güven 16-Nov-13 10:28am    
Capital letters for time uses 24hr format.
"HH" displays hour as 24hr format, whereas "hh" display as 12hr format
mohsenvasefi 16-Nov-13 10:31am    
i know this, but couldn't find its function to use HH unfortunately
i should have a Timer and a DateTimePicker. in timer tick, must write:
C#
private void timer1_Tick(object sender, EventArgs e)
        {
            dateTimePicker1.ResetText();
        }

and select timer interval=999 (because of run time delay) or 1000
 
Share this answer
 
Comments
CHill60 16-Nov-13 10:28am    
Is this meant to be a solution or further details about your question?
mohsenvasefi 16-Nov-13 10:37am    
both

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900