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
  1. Home
  2. General Programming
  3. C#
  4. C# how to keep datetimes independent of regional settings

C# how to keep datetimes independent of regional settings

Scheduled Pinned Locked Moved C#
csharptutorial
6 Posts 5 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.
  • M Offline
    M Offline
    MayukhSen
    wrote on last edited by
    #1

    i am taking the system date as DateTime.Now.Date its giving diffetent values for diferent culture 6/5/2010 12:00:00 AM : for English(United State) 05/06/2010 00:00:00 : for English(United Kingdom) I want my dates in '6/5/2010 12:00:00 AM' how to get date independent of regional settings

    D OriginalGriffO P L 4 Replies Last reply
    0
    • M MayukhSen

      i am taking the system date as DateTime.Now.Date its giving diffetent values for diferent culture 6/5/2010 12:00:00 AM : for English(United State) 05/06/2010 00:00:00 : for English(United Kingdom) I want my dates in '6/5/2010 12:00:00 AM' how to get date independent of regional settings

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      DateTime is just a long counting ticks IIRC - what you are seeing is just the string representation for the culture in question. Specify your own string format, culture or InvariantCulture. PiebaldConsult will be here shortly with his ISO comments!

      Dave

      If this helped, please vote & accept answer!

      Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      1 Reply Last reply
      0
      • M MayukhSen

        i am taking the system date as DateTime.Now.Date its giving diffetent values for diferent culture 6/5/2010 12:00:00 AM : for English(United State) 05/06/2010 00:00:00 : for English(United Kingdom) I want my dates in '6/5/2010 12:00:00 AM' how to get date independent of regional settings

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        As Davey says, DateTime.Now just returns a time - it has no format. When you specify the output format, then you can use the current culture, specify a culture, or fix the format so that it is culture invariant. Have a look here[^] - it shows all the various parts you can use to format your date.

        Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • M MayukhSen

          i am taking the system date as DateTime.Now.Date its giving diffetent values for diferent culture 6/5/2010 12:00:00 AM : for English(United State) 05/06/2010 00:00:00 : for English(United Kingdom) I want my dates in '6/5/2010 12:00:00 AM' how to get date independent of regional settings

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          As others have pointed out, a DateTime is a region independent structure already. What you are talking about is using a format converter to control how it is displayed. Before you look at setting the output of the date to be a particular format, I must ask you to consider how your application is going to be used; people have a specific local regional setting in place and generally expect their dates to be displayed in those formats - this can be critical because it has an effect on the understanding of the date. When I looked at your example, my first thought was that you were talking about the 6th of May because I am based in the UK, by displaying a different regional setting you have skewed my understanding of your data.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          1 Reply Last reply
          0
          • M MayukhSen

            i am taking the system date as DateTime.Now.Date its giving diffetent values for diferent culture 6/5/2010 12:00:00 AM : for English(United State) 05/06/2010 00:00:00 : for English(United Kingdom) I want my dates in '6/5/2010 12:00:00 AM' how to get date independent of regional settings

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Ah, DateTime, a perfect source of confusion around the globe. You might want to read this[^]. It holds some cues, including a reference to the infamous ISO 8601. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


            M 1 Reply Last reply
            0
            • L Luc Pattyn

              Ah, DateTime, a perfect source of confusion around the globe. You might want to read this[^]. It holds some cues, including a reference to the infamous ISO 8601. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              M Offline
              M Offline
              MayukhSen
              wrote on last edited by
              #6

              Thank you for your response. I have found out the solution . I am setting my Application Culture at startup Application.CurrentCulture = new CultureInfo("en-US");

              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