Formatting timeField to use 12hr timeformat "hh:mm a"

I am not so clear on the best way to use 12hr timeformat for timeField in my project.

WHAT DOES NOT WORK:
I am seeing where placing

timeFormat=hh:mm a

in messages.properties does not work properly as it affects the following in screen descriptor:

<timeField id="visitTimeField" property="visitTime" timeMode="H_12"/>

( It affects the mask of the timeField component )

WHAT SEEMS TO WORK:
In order to get 12hr formatting to work, I have to use do the following:
1. Ensure that my messages.properties file does not define “timeFormat”
2. In my Entity editor screen:

<timeField id="visitTimeField" property="visitTime" timeMode="H_12"/>

3. In my Entity browse screen:
Format time to 12hr in groupTable:

<column id="visitTime" width="80" align="CENTER">
                    <formatter class="com.haulmont.cuba.gui.components.formatters.DateFormatter" format="h:mm a"/>
                </column>

Is this the correct way ? Is “timeFormat” no longer to be defined in messages.properties ?

Hi,

timeFormat still can be defined either in message.properties or as a constant value in screen descriptor/controller (see demo). In order to have 12-h mode, you need to define an independent timeMode="H_12" attribute.

Regards,
Gleb

@gorelov, I have tried that but it does not work. I suspect that there is a bug.
Please watch following video recording I made in order to demonstrate the bug:

Video showing bug in using timeFormat=hh:mm a

12hr timeFormat does not work when defined in message.properties
I am using the latest version 7.2.3

Regards,
Robert

Thank you for the video with detailed explanations. The problem is that timeFormat can’t be used to change timeMode to 12-h, i.e. you can’t use a in your timeFormat. As I mentioned above, for the 12-h format, you need to define timeMode="H_12". But you still can use timeFormat to change time format, e.g.:

<timeField timeFormat="hh/mm" timeMode="H_12"/>

Regards,
Gleb

A post was split to a new topic: How to show the time in the lookup with 12 hours