Select to view content in your preferred language

Date format for DateTime field in Editor Widget

1533
6
Jump to solution
01-17-2022 11:33 PM
ZA1
by
Occasional Contributor

Hi,

A feature I am using in Editor widget has a DateTime attribute 

By default the Date/Time fields are in the format of: mm/dd/yyyy

Instead, I need it to be: dd/mm/yyyy

I do not know how to do this change. 

ZA1_0-1642490975106.png

But preferably, when the user clicks the date field a calendar should appear to select a day.

Any help would be greatly appreciated.

 

Thanks!

 

0 Kudos
1 Solution

Accepted Solutions
HeatherGonzago
Esri Contributor

Hi, thanks for asking about this. Unfortunately, there is no direct and easy way to set this right now in the FeatureForm (and hence the Editor since this uses the FeatureForm widget). We are actively working on making this easier for all widgets that make use of dates and will hopefully have a better way to handle this in an upcoming release.

For now, formatting for dates in the FeatureForm is taken directly by the browser. If you're browser's locale was set to "en-GB", the format would flip to dd/mm/yyyy. I realize that this is not the answer you were looking to get. We do hope to make this easier in the near future.

View solution in original post

6 Replies
HeatherGonzago
Esri Contributor

Hi, thanks for asking about this. Unfortunately, there is no direct and easy way to set this right now in the FeatureForm (and hence the Editor since this uses the FeatureForm widget). We are actively working on making this easier for all widgets that make use of dates and will hopefully have a better way to handle this in an upcoming release.

For now, formatting for dates in the FeatureForm is taken directly by the browser. If you're browser's locale was set to "en-GB", the format would flip to dd/mm/yyyy. I realize that this is not the answer you were looking to get. We do hope to make this easier in the near future.

ZA1
by
Occasional Contributor

Thanks for the response @HeatherGonzago, appreciated. 

Unfortunately, there is no direct and easy way to set this right now


As a non-direct way, perhaps:

  1. Hide the original date field in the form
  2. Insert a new input field with the date configuration that I want 
  3. When the user clicks "Add", in the background I replace the date in (1) with (2) 

Could I ask you if you can think of a better approach?

0 Kudos
JohnZachariassen
Occasional Contributor

Hi,

We followed your advice and set the language to Danish. That worked, and the format switched to dd/mm/yyyy. At that time, the ArcGIS Maps SDK for JavaScript version was 4.24. However, after we updated to ArcGIS Maps SDK for JavaScript v. 4.31, the format has switched back to mm/dd/yyyy, even though the browser setting remains unchanged. Is there anything we can do to restore the dd/mm/yyyy format?

0 Kudos
HeatherGonzago
Esri Contributor

Hi @JohnZachariassen  I wonder if you are seeing a slight update that was made for localization in 4.31? The SDK will automatically use the locale defined via the lang attribute on the root html element, or the locale of the browser.  Do you have the locale defined on the root html element? Another thing to try, is to set the locale using intl.setLocale(). This should take care of it if it is not automatically getting picked up by the browser. Take a look at https://developers.arcgis.com/javascript/latest/localization/ for additional info on it. If it still doesn't work, let us know.

0 Kudos
JohnZachariassen
Occasional Contributor

@Hi @HeatherGonzago.

We modified the code by using intl.setLocale(), and now the date format is as we wanted. Thank you for the helpful answer; it is greatly appreciated!

0 Kudos
HeatherGonzago
Esri Contributor

Great, glad to hear it's working out. Thanks for letting us know.

0 Kudos