Re: Modify default behavior of Date.ToString?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thanks to Scott Hansleman for this solution:

The default date format is "G", which according to MSDN is made up of
the short date and LONG time patterns:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp

So all I had to do was replace:

customCulture.DateTimeFormat.ShortTimePattern = "HH:mm:ss"

With:

customCulture.DateTimeFormat.LongTimePattern = "HH:mm:ss"


And it worked.

Tom wrote:
I need to modify the default behavior of Date.ToString() on all pages
of my ASP.Net (2.0) site. I don't need to localize my app (it's an
intranet-only site), but I need to enforce a specific date/time format
sitewide ("MM/dd/yyyy HH:mm:ss") and I don't want to have to write that
each time I have to format a date to string.

I googled CurrentCulture and Date Format, and I found some articles on
customizing the default culture of your machine via the control panel -
that didn't work. Eventhough I was able to set it, it did not get
applied to dates on ASP.Net pages.

Then I tried setting the CurrentCulture for the current thread to a
customized culture object:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load

Dim customCulture As CultureInfo = New CultureInfo("en-US")
customCulture.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy"
customCulture.DateTimeFormat.ShortTimePattern = "HH:mm:ss"
Thread.CurrentThread.CurrentCulture = customCulture

End Sub

That works (sort of), but there are 2 problems:

1) Date.ToString() still renders an AM/PM designator which is not
needed b/c I'm using 24hr time
2) I can put this code into my base page class, but do I really want to
execute this code everytime a page loads? I'd rather set it somewhere
lower in the stack.

Any help would be appreciated.

.



Relevant Pages

  • Re: Word 2000 vs Word 2007
    ... where you'll find the "Style area pane width" setting. ... "Save files in this format" to Word 97-2003 Document. ... icons primarily for text formating and another with more complex tasks. ... both of these I cannot find any method for customizing their contents. ...
    (microsoft.public.word.docmanagement)
  • Modify default behavior of Date.ToString?
    ... each time I have to format a date to string. ... customizing the default culture of your machine via the control panel - ... Protected Sub Page_Load(ByVal sender As Object, ... execute this code everytime a page loads? ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Creating Navigation Buttons
    ... How do I format the web pages to hold those buttons? ... What commands split the page and keep the "buttons" part at the top of each Page. ... then I would look into customizing the buttons? ... Thanks again for everybodys help! ...
    (microsoft.public.frontpage.client)
  • Re: Calendar Date Format
    ... Trying to get this format returned when selecting a date on a calendar ... Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ... Dim selection As String = Format, ...
    (microsoft.public.dotnet.languages.vb)
  • Calendar Date Format
    ... Trying to get this format returned when selecting a date on a calendar ... Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ... Dim selection As String = Format, ...
    (microsoft.public.dotnet.languages.vb)