How to use Custom ResourceBundle of Locale to print date time using date time formatter(Java 8)?

204 Views Asked by At

I am trying to get support of multiple locales in my code. For this I need to have support of date and time in different locales. But the restriction is this date and time are not completely localised. For example,

27 July 2019, Saturday, 11:24 AM

for hi-IN gets tranlated to

27 जुलाई 2019, शनिवार, 11:24 पूर्वाह्न

but the output i need is:

27 जुलाई 2019, शनिवार, 11:24 AM

or

27 जुलाई 2019, Saturday, 11:24 AM

Needs to know whether this is the right approach or there is some other way to solve this properly.

I am try a pass a customised locale to DateTimeFormatter For example:

return DateTimeFormat.forPattern(format).withLocale(new Locale("hi", "IN", "custom"));

and trying to have a resource bundle like

sun.text.resources.hi.FormatData_hi_IN_custom

same as

sun.text.resources.hi.FormatData_hi_IN

but replaced पूर्वाह्न with AM etc. But this is not getting picked up.

The custom resource file I am using

package sun.util.resources.hi;

import sun.util.resources.ParallelListResourceBundle;

public class FormatData_hi_IN_custom extends ParallelListResourceBundle {
    public FormatData_hi_IN_custom() {
    }

    protected final Object[][] getContents() {
        return new Object[][]{{"MonthNames", new String[]{"जनवरी", "फ़रवरी", "मार्च", "अप्रैल", "मई", "जून", "जुलाई", "अगस्त", "सितंबर", "अक्\u200dतूबर", "नवंबर", "दिसंबर", ""}}, {"MonthAbbreviations", new String[]{"जनवरी", "फ़रवरी", "मार्च", "अप्रैल", "मई", "जून", "जुलाई", "अगस्त", "सितंबर", "अक्\u200dतूबर", "नवंबर", "दिसंबर", ""}}, {"MonthNarrows", new String[]{"ज", "फ़", "मा", "अ", "म", "जू", "जु", "अ", "सि", "अ", "न", "दि", ""}}, {"DayNames", new String[]{"रविवार", "सोमवार", "मंगलवार", "बुधवार", "गुरुवार", "शुक्रवार", "शनिवार"}}, {"DayAbbreviations", new String[]{"रवि", "सोम", "मंगल", "बुध", "गुरु", "शुक्र", "शनि"}}, {"DayNarrows", new String[]{"र", "सो", "मं", "बु", "गु", "शु", "श"}}, {"AmPmMarkers", new String[]{"AM", "PM"}}, {"Eras", new String[]{"ईसापूर्व", "सन"}}, {"short.Eras", new String[]{"ईसापूर्व", "सन"}}, {"NumberElements", new String[]{".", ",", ";", "%", "०", "#", "-", "E", "‰", "∞", "�"}}, {"TimePatterns", new String[]{"h:mm:ss a z", "h:mm:ss a z", "h:mm:ss a", "h:mm a"}}, {"DatePatterns", new String[]{"EEEE, d MMMM, yyyy", "d MMMM, yyyy", "d MMM, yyyy", "d/M/yy"}}, {"DateTimePatterns", new String[]{"{1} {0}"}}, {"DateTimePatternChars", "GyMdkHmsSEDFwWahKzZ"}};
    }
}

and trying to run this:

        System.out.println(DateTimeFormat.forPattern("dd-MMM-YYYY, EEE, HH-mm a").withLocale(new Locale("hi", "IN", "custom")).print(System.currentTimeMillis()));
0

There are 0 best solutions below