Showing dates in appropriate locale

Hi,

I want to show dates in the appropriate user locale but this seems hard to do. Consider this example:

XML descriptor:


<label id="newsDateLabel"
                       datasource="newsDs"
                       htmlEnabled="true"
                       property="newsDate"
                       stylename="lblDate"/>

So there is a label which should show a date. Ideally, I would like to have the platform automatically provide the date in the format of user locale. I know this format is specified somewhere in the messages.properties in the platform but it does not seem to be applied. Neither in the situation shown here nor automatically in tables and such.

Do you really need to process the format through code, like this:


String dateStr = Datatypes.get(Date.class).format(date, AppBeans.get(UserSessionSource.class).getLocale());

This would make a huge effort to get all dates represented correctly. I am expecting the platform to handle this, correct?

Again, any help appreciated.

Could you try to set the desired format in Project properties > Available locales > Show data format strings > dateFormat/dateTimeFormat? Then Studio will create appropriate changes in main message packs. See also Datatype.

Please let us know if it doesn’t work for you.

Hi Konstantin, excellent answer and exactly what I was looking for. Thanks! It solved all problems I had.