>I am trying to format a DateTime using ToString(). I am using the "t" formating for short time. The system is configured to use
> HH.mm.ss but the result formatted time is in the default short time of h.mm tt. I have tried passing in a DateTimeFormatInfo that
[quoted text clipped - 9 lines]
> KMSYS Worldwide, Inc.
> http://www.kmsys.com
DateTime.Now.ToString(Thread.CurrentThread.CurrentCulture) does produce a string with the date and time in the format specified in
the Regional Options. That gets me closer. Thank you.
However, I am still having a problem.
I tried DateTime.Now.ToString("t",Thread.CurrentThread.CurrentCulture) because I just wanted the time portion and I expected that
it would display the time in the format specified in the Regional Options, but instead it continues to display h.mm tt.
t format says, it is associated with the ShortTimePattern of the DateTimeFormatInfo
Is this a bug, bad documentation, wishful thinking on my part, or fill in the blank?
Thanks
>This should do if for you:
>
[quoted text clipped - 17 lines]
>> KMSYS Worldwide, Inc.
>> http://www.kmsys.com
-------------------------------------------
Roy Chastain
KMSYS Worldwide, Inc.
http://www.kmsys.com
"Peter Huang" [MSFT] - 19 Aug 2005 07:05 GMT
Hi
Based on my test, the culture will work as expected.
Here is my test sample.
MsgBox(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern)
'current format H:mm:ss
MsgBox(DateTime.Now.ToString("t",
Thread.CurrentThread.CurrentCulture)) 'Here the time will be H:mm:ss format
Dim o As CultureInfo = Thread.CurrentThread.CurrentCulture.Clone()
o.DateTimeFormat.ShortTimePattern = "h:mm:ss"
Thread.CurrentThread.CurrentCulture = o
MsgBox(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern)
MsgBox(DateTime.Now.ToString("t",
Thread.CurrentThread.CurrentCulture)) 'Here the time will be h:mm:ss
format.
So I think you may try to check the
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern.
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Roy Chastain - 19 Aug 2005 12:20 GMT
I have looked at the ShortTimePattern in the returned culture and yes the output matches it.
The question is, how do I get ToString to format a date/time the way the customer wants it formatted? (Note in this case, the way
the customer wants it formatted is the way he defined in the regional settings.)
Is this something as simple as a problem with the words Short and Long when applied to time patterns. I noticed that there are
also long time patterns and they seem to have hh instead of h. Could it be that the regional settings are really showing up in
the long time pattern instead of the short one. (Long and short dates make sense to me - Long and short times do not - At least
not in US-english)
Thanks
>Hi
>
[quoted text clipped - 24 lines]
>Get Secure! - www.microsoft.com/security
>This posting is provided "AS IS" with no warranties, and confers no rights.
-------------------------------------------
Roy Chastain
KMSYS Worldwide, Inc.
http://www.kmsys.com
"Peter Huang" [MSFT] - 22 Aug 2005 13:38 GMT
Hi
If you have a look at the regional setting, you will find that there is
short date, long date and a time. But there is no a short/long time setting.
So it seems that the .net framework will map the short date, long date. Map
the long time to the time in the regional setting.
It did not map the short time, because there is no such one.
Try to run the code below.
'Four date/time formatting
MsgBox(DateTime.Now.ToShortTimeString())
MsgBox(DateTime.Now.ToLongTimeString())
MsgBox(DateTime.Now.ToShortDateString())
MsgBox(DateTime.Now.ToLongDateString())
If you run the code below, you will find if you change the time in the
regional setting, the long time will change. But the shorttime and short
time pattern will not change. But the ToShortTimeString and
DateTime.Now.ToString("t") accord with ShortTimePattern.
MsgBox(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern.T
oString())
MsgBox(DateTime.Now.ToString("t"))
MsgBox(Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern.To
String())
So for your scenario, I think you may try to use the long time instead, if
necessary you can exact the short time from the long time string.
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Roy Chastain - 22 Aug 2005 14:54 GMT
Thanks
I had come to that conclusion. Thanks for confirming.
>Hi
>
[quoted text clipped - 35 lines]
>Get Secure! - www.microsoft.com/security
>This posting is provided "AS IS" with no warranties, and confers no rights.
-------------------------------------------
Roy Chastain
KMSYS Worldwide, Inc.
http://www.kmsys.com
"Peter Huang" [MSFT] - 23 Aug 2005 07:34 GMT
Hi
Thanks for your reply and glad to see that you have worked out.
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.