Fabian1648 2 Posted August 3, 2022 Hello, Is it possible to change the regional settings of an Android device via Delphi code? If so, how? Thank you Share this post Link to post
Sherlock 663 Posted August 3, 2022 For the complete device or only for your application? Share this post Link to post
Fabian1648 2 Posted August 4, 2022 I have a problem with FormatSettings.ShortDateFormat: When I use it to display a date according to the country standard (e.g. the order "day, month, year" is not suitable in the USA), the year is only displayed with 2 characters. I'd like to take advantage of the default date format defined by the Android device OS but force the year to be displayed with 4 characters instead of 2. If I force the date format (example with a "dd mm yyyy"), I will lose the automatic adaptation of the date format according to the country... Share this post Link to post
Lajos Juhász 293 Posted August 4, 2022 Why would you like to change the regional settings for that case? Use a custom format to convert the date to string. Share this post Link to post
Sherlock 663 Posted August 4, 2022 Have you tried TFormatSettings.LongDateformat? Share this post Link to post
Fabian1648 2 Posted August 5, 2022 (edited) 23 hours ago, Lajos Juhász said: Why would you like to change the regional settings for that case? Use a custom format to convert the date to string. When you have a software that is used in different countries, the date display format changes from one time to another (In France, you will have a "dd/mm/yyyy", in the USA a "mm-dd-yyyy", etc.). If you use a custom format in the code, you will have to create a custom format for each country!!!!!!!!!! So, I would simply force the display of the year with 4 characters instead of 2... Edited August 5, 2022 by Fabian1648 Share this post Link to post
Lajos Juhász 293 Posted August 5, 2022 Just now, Fabian1648 said: When you have a software that is used in different countries, the date display format changes from one time to another (In France, you will have a "dd/mm/yyyy", in the USA a "mm-dd-yyy", etc.). If you use a custom format in the code, you will have to create a cutom format for each country!!!!!!!!!! If you change the regional settings in your application you will change it in all of the countries the same thing as far as I can see. Share this post Link to post
Fabian1648 2 Posted August 5, 2022 2 minutes ago, Lajos Juhász said: If you change the regional settings in your application you will change it in all of the countries the same thing as far as I can see. Here is my problem: Why the default TFormatSettings.ShortDateformat displays the year with 4 characters under Windows, but only with 2 characters under Android? Isn't there a way to notify Android that you want the year with 4 characters instead of 2 without changing the regional settings? Share this post Link to post
Fabian1648 2 Posted August 5, 2022 23 hours ago, Sherlock said: Have you tried TFormatSettings.LongDateformat? I have already tried TFormatSettings.LongDateformat... Share this post Link to post
Lajos Juhász 293 Posted August 5, 2022 You failed to show us an example where are you have a problem. You can use FormatDateTime or DateToStr with yuor own format settings. Share this post Link to post
Vandrovnik 214 Posted August 5, 2022 4 hours ago, Fabian1648 said: Here is my problem: Why the default TFormatSettings.ShortDateformat displays the year with 4 characters under Windows, but only with 2 characters under Android? Isn't there a way to notify Android that you want the year with 4 characters instead of 2 without changing the regional settings? You can still use: var MyFormat: TFormatSettings; MyFormat:=TFormatSettings.Create; // obtains default settings if pos('yyyy', MyFormat.ShortDateFormat)<=0 then MyFormat.ShortDateFormat:=StringReplace(MyFormat.ShortDateFormat, 'yy', 'yyyy', []); ... DateToStr(now, MyFormat); 1 Share this post Link to post
Fabian1648 2 Posted August 5, 2022 4 hours ago, Lajos Juhász said: You failed to show us an example where are you have a problem. You can use FormatDateTime or DateToStr with yuor own format settings. 1) If you use FormatDateTime to define in your Delphi code a custom date format as "yyyy-mm-dd", you will have this format regardless of the country where you use the software: 2022-08-05 in France, 2022-08-05 in USA, 2022-08-05 in Deutschland or in Japan. Each country has his standard. In France, the date format is "05/08/2022" and not "2022-08.05"! That's why the regional settings of an OS exist! 2) Our software must be used worldwide. The date format must be adapted for the country where it is used. 3. We don't want to replace the regional settings of the OS with Delphi code that specifies settings for every country in the world! We want that the regional settings display date with 4 characters ans not 2 for the year. That's it! Share this post Link to post
Fabian1648 2 Posted August 5, 2022 43 minutes ago, Vandrovnik said: You can still use: var MyFormat: TFormatSettings; MyFormat:=TFormatSettings.Create; // obtains default settings if pos('yyyy', MyFormat.ShortDateFormat)<=0 then MyFormat.ShortDateFormat:=StringReplace(MyFormat.ShortDateFormat, 'yy', 'yyyy', []); ... DateToStr(now, MyFormat); Great! This is exactly what I was looking for! Your code uses the date format provided by the OS but forces the display of the year to 4 characters. Thanks a lot Vandrovnik! Share this post Link to post
Lajos Juhász 293 Posted August 5, 2022 Well, you're still changing the year from 2 digits to 4. Anyway Vandrovnik gave you the code I would use. Share this post Link to post
Fabian1648 2 Posted August 5, 2022 Thank you all for your help. The problem is solved. Share this post Link to post