Android Question Date - International Format

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

I am based in FL, USA. Today is August 7, 2014. The code below will generate 08/07/2014 in the log.

B4X:
Dim dt1 As Double
dt1=DateTime.Now
Log (DateTime.Date(dt1))

In Europe and most Latin American countries, 08/07/2014 would be interpreted as July 8, 2014 (dd/mm/yyyy). In essence, in the US, the results of the code are in mm/dd/yyyy format.

Questions:
1. Does B4A automatically detect country of the device and format accordingly?
or if not,
What do I have to do for dates stored in ticks to be properly formatted based on the device country?
2. How do I test location - make my device look like it is not in the USA?
3. Would DateParse also automatically detect the country format?

Any and all help will be welcomed. Thank you in advance for your help.

Best regards.

Sandy
 

tdocs2

Well-Known Member
Licensed User
Longtime User
B4A doesn't detect anything but Android does, yes, it will be localized, the app will use the format for the corresponding country.

Gee, What took you so long, NJ? A whole 4 minutes!!!

This sounds too good to be true, so forgive me for seeking confirmation from you.

If a user in Argentina or in France, is using my app, the code above will actually generate 07/08/2014 for August 7, 2014?
AND
If I parse 07/08/2014 in these two countries, it will generate the ticks for August 7, 2014?

Thank you and best regards.

Sandy

PS Can I test this?
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You can try changing the Date and time format under Settings -> Date and Time, here in the US it defaults to mm/dd/yy but for other countries default to whatever format they use.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
You can try changing the Date and time format under Settings -> Date and Time, here in the US it defaults to mm/dd/yy but for other countries default to whatever format they use.

The test was not successful.

Changed Date Time Settings to 31/12/2014 on a Nexus 7 Android4.4 and on an Asus Transformer Android 4.0.

B4X:
Dim dt1 As Double
dt1=DateTime.Now
Log (DateTime.Date(dt1))

results in 08/07/2014 and not on 07/08/2014.

Any thoughts? I would like to test it.

Thanks for your help.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Maybe you need to set the default-output. This means; ask the user which format he wnt to use and then set this format fixed for this user; on app start you set the wanted format with
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
See DateTime docu. Also see here.

DateFormat AsString
Gets or sets the format used to parse date strings.
The default pattern is MM/dd/yyyy (04/23/2002 for example).

"parse" in this case means that this pattern is used too when you OUTPUT a date with DateTime methods....
 
Last edited:
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Don and Erel.

Last night, I had tried the DateTime.DateFormat = DateTime.DeviceDefaultDateFormat and had also thought of making the date format a setting as Don had suggested. However, I was not sure whether either of these would be the correct or best way to handle this foundational requirement.

It is great (and I am very grateful) to get confirmation from Erel and Don since it gives me assurance that these are the best solutions for the date requirement. Certainly, both these approaches could be deemed as BEST PRACTICES for dealing with dates in apps to be deployed internationally.

Best regards.

Sandy

PS I also considered:
DateTime.DateFormat="yyyy-MM-dd"' which is ISO 8601 Standard.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…