|
-
Feb 27th, 2007, 07:33 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Masked Textbox 24 Hour Clock
I have a masked textbox on my form which has a format of 'hh:mm'
However this gives me the time in 12 hour format whereas I want it in 24 hour format.
From reading on the web I understand that if I change the format to 'HH:mm' then this will give me what I want - However this doesn't work (all it does is change the format back to hh:mm)
Does anyone know how I can fix this ?
-
Feb 27th, 2007, 07:43 AM
#2
Re: [2005] Masked Textbox 24 Hour Clock
Can you show your code?
I know this isn't a masked textbox example but using this code works fine:
Code:
MessageBox.Show(Date.Now.ToString("hh:mm"))
MessageBox.Show(Date.Now.ToString("HH:mm"))
How are you doing the formatting??
This should also work for the Masked textbox:
Code:
Me.MaskedTextBox1.Text = Date.Now.ToString("HH:mm")
'Or
Me.MaskedTextBox1.Text = Date.Now.ToString("hh:mm")
Last edited by stimbo; Feb 27th, 2007 at 07:49 AM.
-
Feb 27th, 2007, 08:05 AM
#3
Re: [2005] Masked Textbox 24 Hour Clock
 Originally Posted by Jonny1409
I have a masked textbox on my form which has a format of 'hh:mm'
However this gives me the time in 12 hour format whereas I want it in 24 hour format.
From reading on the web I understand that if I change the format to 'HH:mm' then this will give me what I want - However this doesn't work (all it does is change the format back to hh:mm)
Does anyone know how I can fix this ?
Hi,
You could use the Clockmode Enumeration for that.
Here's the link;
http://msdn2.microsoft.com/en-us/lib...clockmode.aspx
Wkr,
sparrow1
-
Feb 27th, 2007, 08:13 AM
#4
Re: [2005] Masked Textbox 24 Hour Clock
Is there any reason you can't use a datetimepicker?
-
Feb 27th, 2007, 08:16 AM
#5
Re: [2005] Masked Textbox 24 Hour Clock
Sparrow, you really should read those MSDN topics a little more carefully before posting. That page relates specifically to the POS for .NET SDK. Not many developers will have the Microsoft.PointOfService namespace available to them.
As for displaying the time, I'd suggest using a DateTimePicker with the Format property set to Custom, the CustomFormat property set to "HH:mm" and the ShowUpDown property set to True. You can't set a MaskedTextBox to show specifically 24 hour time. The closest you can get is "00:00" for the mask, which still leaves the job of checking that the mask is full and validating the text to the developer. The DateTimePicker will do it all for you.
-
Feb 27th, 2007, 11:09 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] Masked Textbox 24 Hour Clock
Hi Stimbo,
I'm using the property as opposed to writing it in code. Thanks for the advice though.
Sparrow, thanks for your advice, although I haven't yet looked at the link.
Stanav and jmcilhinney, Thanks for your advice - I'll use a DateTimePicker instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|