Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Date Format

Date Format

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netwindows-adminquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alwinSCH
    wrote on last edited by
    #1

    Hi to All, I was recently trying to develop a website in where i display a date in a textbox ----> txtdatin.Text = FormatDateTime(Date.Today, vbShortDate) So VBShortDate takes the format of the date options in Regional settings? (dd/MM/jjjj) So far so good! On my own developpers pc When the application is finished i would publish it for real! The regional settings are exactly the same, but my date is displayed (d/MM/jjjj) This is not correct because i work on that date! It should also be dd/MM/jjjj Is there another thing i should configure in IIS, ASP.net2.0 Or is there another function i could use instead of vbShortDate directly set the format right? Thanks for your support

    G 1 Reply Last reply
    0
    • A alwinSCH

      Hi to All, I was recently trying to develop a website in where i display a date in a textbox ----> txtdatin.Text = FormatDateTime(Date.Today, vbShortDate) So VBShortDate takes the format of the date options in Regional settings? (dd/MM/jjjj) So far so good! On my own developpers pc When the application is finished i would publish it for real! The regional settings are exactly the same, but my date is displayed (d/MM/jjjj) This is not correct because i work on that date! It should also be dd/MM/jjjj Is there another thing i should configure in IIS, ASP.net2.0 Or is there another function i could use instead of vbShortDate directly set the format right? Thanks for your support

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      It's not using the regional settings that you think it is. It's using the settings of the server, not the client. The solution is to never use the default regional settings, unless you have specified them in the configuration files. You can create a CultureInfo object to use for formatting. For an example, for swedish format I use: Dim culture as CultureInfo culture = new CultureInfo(1053) Then you use that to format the date: txtdatin.Text = Date.Today.ToString("d", culture) You can also specify an exact format: txtdatin.Text = Date.Today.ToString("dd/MM/yyyy") --- b { font-weight: normal; }

      A 1 Reply Last reply
      0
      • G Guffa

        It's not using the regional settings that you think it is. It's using the settings of the server, not the client. The solution is to never use the default regional settings, unless you have specified them in the configuration files. You can create a CultureInfo object to use for formatting. For an example, for swedish format I use: Dim culture as CultureInfo culture = new CultureInfo(1053) Then you use that to format the date: txtdatin.Text = Date.Today.ToString("d", culture) You can also specify an exact format: txtdatin.Text = Date.Today.ToString("dd/MM/yyyy") --- b { font-weight: normal; }

        A Offline
        A Offline
        alwinSCH
        wrote on last edited by
        #3

        Yes I know, it uses the regional settings of the server, I set them like my development pc! So it has to work the same way! And how does such cultureInfo work? Could you give a little explanation? Thnx

        G 1 Reply Last reply
        0
        • A alwinSCH

          Yes I know, it uses the regional settings of the server, I set them like my development pc! So it has to work the same way! And how does such cultureInfo work? Could you give a little explanation? Thnx

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          No, it doesn't work the same way. Exactly how it works may differ depending on the version of Windows. So setting the regional settings of the server is not a good way of controlling the regional settings of the ASP.NET code. A CultureInfo object contains format providers for formatting dates, numbers, currency and such. Whenever a value like this is converted to a string, a format provider is always used. If you don't specify a format provider or CultureInfo, the default culture for the thread is used, and you can't know what that is unless you specify it yourself. --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups