Francesco Galgani
Francesco Galgani

Reputation: 6249

Localized date and time in Codename One

This question is not referred to generic Java, but to Codename One only.

I tried:

SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.FULL, SimpleDateFormat.FULL).format(new Date());

that returns (both on Simulator and on Android):

Sun Jan 13 14:41:35 CET 2019

How can I get a localized version of date and time? I mean localized automatically, without the need that I specify the format for each locale.

For example, when I run the app on an Italian smartphone, I expect an equivalent string like:

13 gennaio 2019, 14:41:35

If it's possible, without the name of the day of week and without "CET".

I noted that (SimpleDateFormat.FULL, SimpleDateFormat.FULL) or (SimpleDateFormat.SHORT, SimpleDateFormat.SHORT) return the same string in this example.

Upvotes: 1

Views: 151

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

You need to use L10NManager which includes formatters for date/time e.g.:

String asString = L10NManager.getInstance().formatDateLongStyle(date);

Upvotes: 1

Related Questions