Codename One - using L10NManager instead of DateFormat (deprecated) to get current Locale date-time format

Viewed 95

My CodenameOne app (iOS port of an Android app) shows a date-time format example to the user, according to the Locale.

This is the Java code in my Android app:

static String getTheCurrentLocaleDateTimeFormatString() {
    return ((SimpleDateFormat) DateFormat.getDateTimeInstance()).toLocalizedPattern();
}

For example in my Locale I get this string:

dd MMM y HH:mm:ss

No modification to the app design can be done on this.

Documentation here : https://www.codenameone.com/javadoc/java/text/DateFormat.html

says DateFormat is deprecated and has issue on some platforms, like iOS itself. It is only used for this, I left it in my Android app by the way.

However, I can't use its methods because they are not the same in CodenameOne, if I am not wrong.

Documentation says to use L10NManager instead, but I have to change the code.

What is the right way to use L10NManager to achieve the same goal?

1 Answers

You can use L10NManager like this:

String t = L10NManager.getInstance().formatDateTime(date);

We support SimpleDateFormat too but it's a bit more limited. We have a version of it in com.codename1.l10n which works more consistently across platforms.

Related