Tag Archives: time

Use a symbiote to graphically select hours in C#

This example modifies the previous example Graphically select hours in C# so it uses a symbiote class. That example shows how to use a PictureBox to let the user select a range of hours. If you want to let the … Continue reading

Posted in controls, graphics, user interface | Tagged , , , , , , , , , , , , | 1 Comment

Graphically select hours in C#

The DateTimePicker control lets you select dates and date ranges, but there’s no standard control that lets you select hours. This example shows one way to do this with a PictureBox. A big part of this program is the DrawHours … Continue reading

Posted in controls, graphics, user interface | Tagged , , , , , , , , , , , | 1 Comment

Add a ToString extension method to the TimeSpan structure in C#

Until .NET Framework version 4.0, you could not pass the TimeSpan structure’s ToString method a format string, so the result was always in the form hh:mm:ss.fffffff where hh is hours, mm is minutes, ss is seconds, and fffffff is 7 … Continue reading

Posted in extension methods, parsing | Tagged , , , , , , , , , , | 2 Comments

Get the current time from the NIST server in C#

This example, courtesy of Adam Benson, shows how you can get the current time from the NIST atomic clock server. (I’ve reformatted it slightly to make it fit better on the blog page.) The key to the program is the … Continue reading

Posted in miscellany, system | Tagged , , , , , , , , , , , , , , | 1 Comment

Measure elapsed time in C#

For most tasks, you can measure elapsed time with the Stopwatch or DateTime classes. To use the Stopwatch class, create a Stopwatch object. Use its Start and Stop methods to start and stop it. If you use Start after stopping … Continue reading

Posted in performance, system | Tagged , , , , , , , , , , , | Leave a comment