SWT DateTime format change

2019-06-23 17:55发布

问题:

I'm using a DateTime SWT component, and it has an American format when displayed (mm/dd/yyyy).

Is there any way to change the format to dd/mm/yyyy ?

回答1:

DateTime uses the OS specific user preferences to format the date. (On Windows these are the Regional and Language Options in the system settings).

A possible workaround is described here (scroll down to the latest two entries). But I haven't tried this myself.



回答2:

You need to set the locale to change the date format, e.g. to Italy who use dd/mm/yyyy:

Locale.setDefault(Locale.ITALY);

An alternative is the Nebula CDateTime Widget: https://www.eclipse.org/nebula/widgets/cdatetime/cdatetime.php

(btw: if you are using Linux there is a bug regarding the locale: https://bugs.eclipse.org/bugs/show_bug.cgi?id=248075)