Globalization issues with Dates
-
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
-
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
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.
-
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
-
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
-
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
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
-
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
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