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. Mobile Development
  3. Android
  4. Globalization issues with Dates

Globalization issues with Dates

Scheduled Pinned Locked Moved Android
csharpasp-netdatabasecom
6 Posts 4 Posters 14 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.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    Good Day Everyone i am doing an app and all is good. My app changes the language based on the device settings as they change. now i hit a wall when i saw dates in Traditional Chinese appeared like this 2019/12/29 下午 09:14:37 obviously when i try to search from the database i get the error that the date is not in the correct format. so since i will do this with different other languages , i want to create some universal or generic way to handle this dates. so i wrote this public static DateTime Convert_To_System_DateTime(string input) { return DateTime.ParseExact(input, "yy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); } and still i am not getting any joy. Thanks

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

    L 2 Replies Last reply
    0
    • V Vimalsoft Pty Ltd

      Good Day Everyone i am doing an app and all is good. My app changes the language based on the device settings as they change. now i hit a wall when i saw dates in Traditional Chinese appeared like this 2019/12/29 下午 09:14:37 obviously when i try to search from the database i get the error that the date is not in the correct format. so since i will do this with different other languages , i want to create some universal or generic way to handle this dates. so i wrote this public static DateTime Convert_To_System_DateTime(string input) { return DateTime.ParseExact(input, "yy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); } and still i am not getting any joy. Thanks

      Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      A date is stored internally as a count, not as a string. It becomes a string after formatting it for a specific culture. Are you storing your dates as a string, or a DateTime? If it is in XML, try converting everything to the ISO variants.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      1 Reply Last reply
      0
      • V Vimalsoft Pty Ltd

        Good Day Everyone i am doing an app and all is good. My app changes the language based on the device settings as they change. now i hit a wall when i saw dates in Traditional Chinese appeared like this 2019/12/29 下午 09:14:37 obviously when i try to search from the database i get the error that the date is not in the correct format. so since i will do this with different other languages , i want to create some universal or generic way to handle this dates. so i wrote this public static DateTime Convert_To_System_DateTime(string input) { return DateTime.ParseExact(input, "yy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); } and still i am not getting any joy. Thanks

        Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        What is the content of the input variable?

        V 1 Reply Last reply
        0
        • L Lost User

          What is the content of the input variable?

          V Offline
          V Offline
          Vimalsoft Pty Ltd
          wrote on last edited by
          #4

          Good Day Since the phone was changed to Chinese Traditional , i had to specify the system date to var finaldate = input.ToString("yyyy-MM-dd hh:mm:ss tt", CultureInfo.CreateSpecificCulture("en-US")); and this work for the input "2019/12/29 下午 09:14:3"

          Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

          Richard DeemingR E 2 Replies Last reply
          0
          • V Vimalsoft Pty Ltd

            Good Day Since the phone was changed to Chinese Traditional , i had to specify the system date to var finaldate = input.ToString("yyyy-MM-dd hh:mm:ss tt", CultureInfo.CreateSpecificCulture("en-US")); and this work for the input "2019/12/29 下午 09:14:3"

            Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Vimalsoft(Pty) Ltd wrote:

            CultureInfo.CreateSpecificCulture("en-US")

            Rather than creating a new culture on every call, you could just use CultureInfo.InvariantCulture, which uses US formatting rules for everything. CultureInfo.InvariantCulture Property (System.Globalization) | Microsoft Docs[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            • V Vimalsoft Pty Ltd

              Good Day Since the phone was changed to Chinese Traditional , i had to specify the system date to var finaldate = input.ToString("yyyy-MM-dd hh:mm:ss tt", CultureInfo.CreateSpecificCulture("en-US")); and this work for the input "2019/12/29 下午 09:14:3"

              Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com

              E Offline
              E Offline
              Exoskeletor
              wrote on last edited by
              #6

              are you storing them as DateTime or as string? it's quite difficult to handle dates stored as string, there are a lot of cases that you have to consider. Either store it as DateTime or as byte and convert bytes to datetime. Never save a Date as a string unless you want only to display that value and not do calculations

              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