Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

displaying the time on each form

is there a way of displaying the time on each form in vb, in either 12 hr format or 24 hour format...depending on what the user wants to use?
[141 byte] By [MonaVohra] at [2007-11-11 10:31:54]
# 1 Re: displaying the time on each form
Are you asking how to display the time in 12- or 24-hour format? If so, you may use the ToString method of the DateTime class: http://msdn2.microsoft.com/en-us/library/zdtaw1bw.aspx
Phil Weber at 2007-11-11 20:47:31 >
# 2 Re: displaying the time on each form
is there a way of displaying the time on each form in vb, in either 12 hr format or 24 hour format...depending on what the user wants to use?Yes, the 'now' object will return the current date and time. You can format the information however you want. There are some predefined output settings available. If you don't like the options the .ToString method will take a format string and return the date/time in whatever format you choose. So for example Now.ToLongTimeString 'Outputs time like this 12:07:22 AM
Now.ToString("HH:mm:ss") 'This will display the time in 24 hour format
You can find more information by following this link on date/time formatting strings.http://msdn2.microsoft.com/en-us/library/97x6twsz.aspx
To update the time you'll need to add a timer with an interval of 1 second (assuming you want that kind of accuracy). In the tick event just update the time on the form. Obviously the user will have to be able to select a preference and that preference will need to be stored and recalled. You could then choose which format to display based on the users choice.
TwoFaced at 2007-11-11 20:48:32 >