Locale specific DateTime formatting

The locale for my installation is set to nl-NL (visible in Paper UI). However, if I format a DateTime item to show textual day of the week or month name, I get the english text, e.g. “Saturday” and “February”. It looks like the java formatter does not respect the OH setting. My Raspberry Pi uses the en_GB locale. My guess is, this is used by Java.

Am I correct?

Shouldn’t the OH locale be used instead?

$ locale


To get the weekdays in German language I had to set my Pi to de_DE through raspi-config.

1 Like

For the formatting of dates and numbers OH currently uses the default locale. I have already created an issue for this problem: https://github.com/eclipse/smarthome/issues/2714

I don’t want to change the locale of my OS. Instead (for testing purposes) I modified the karaf launch script /usr/share/openhab2/runtime/bin/karaf and added these lines:

                -Duser.country=NL \
                -Duser.language=nl \

After a restart, my Java is now running with the Dutch locale. :smile:

However, I am afraid that this file will be overwritten after an update.

So the question is, is there a way (file, environment variable) to hook into the script?

I saw this:


            ${KARAF_EXEC} "${JAVA}" ${JAVA_OPTS} \
                -Duser.country=NL \
                -Duser.language=nl \
                -Djava.endorsed.dirs="${JAVA_ENDORSED_DIRS}" \
                -Djava.ext.dirs="${JAVA_EXT_DIRS}" \
                -Dkaraf.instances="${KARAF_HOME}/instances" \
                -Dkaraf.home="${KARAF_HOME}" \
                -Dkaraf.base="${KARAF_BASE}" \
                -Dkaraf.data="${KARAF_DATA}" \
                -Dkaraf.etc="${KARAF_ETC}" \
                -Dkaraf.restart.jvm.supported=true \
                -Djava.io.tmpdir="${KARAF_DATA}/tmp" \
                -Djava.util.logging.config.file="${KARAF_BASE}/etc/java.util.logging.properties" \
                ${KARAF_SYSTEM_OPTS} \
                ${KARAF_OPTS} \
                ${OPTS} \
                -classpath "${CLASSPATH}" \
                ${MAIN} "$@"

and couldn’t find all of the OPTS variables in the script. Perhaps one of these can be set as environment variables before the script is run?


Responding to an old topic as this is the top result on how to use another locale for OpenHAB than the system default.

Yes, as you write we only need to set the -D options in an enivronment variable before starting the script. How that is best done will depend on your type of installation and personal preferences. One way is to set the KARAF_OPTS shell variable as that is added to the command line by the service startup script.

For example, in Openhabian you can add these lines to the startup script /etc/default/openhab2, preferably just below the JAVA_OPTIONS section:

KARAF_OPTS=”-Duser.country=SE -Duser.language=sv”

Then restart OpenHAB. It will now use your favourite locale (in this case Swedish). This seems to work well with Basic UI. However I see no effect on the Paper UI “Control” page. YMMV.

As usual with locales, the locale must be generated before it can be used. If using Openhabian just sudo openhabian-config then select System Settings | Set System Locale and enable your preferred country/language combo in the list, e.g. sv_SE.UTF-8. (But don’t change the system default.)