How can we change date/time language in android without changing the device language.
Below is my current code. below code changes according to the device language. but i want to change without changing the device language settings
public static String formatTime(Date time)
    {
        String timeFormat = UserSettingManager.getUserSetting(UserSettingManager.PREF_TIME_FORMAT);
        if(StringUtils.isEmptyOrWhitespace(timeFormat))
        {
            timeFormat = DEFAULT_TIME_FORMAT;
        }
    SimpleDateFormat formatter;
    try
    {
        formatter = new SimpleDateFormat(timeFormat);            
    }
    catch(Exception e)
    {
        formatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT);
    }
    return formatter.format(time);
}
                try this:
public static String formatTime(Date time, Locale locale){
    String timeFormat = UserSettingManager
                           .getUserSetting(UserSettingManager.PREF_TIME_FORMAT);
    if(StringUtils.isEmptyOrWhitespace(timeFormat)){
        timeFormat = DEFAULT_TIME_FORMAT;
    }
    SimpleDateFormat formatter;
    try {
        formatter = new SimpleDateFormat(timeFormat, locale);            
    } catch(Exception e) {
        formatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT, locale);
    }
    return formatter.format(time);
}
And then like
Log.e("CHINESE DATE", formatTime(new Date(), Locale.CHINESE));
If you don't find a locale in the default list you can instantiate one using its constructor :
Locale spanish = new Locale("es", "ES");
So it becomes
Log.e("SPANISH DATE", formatTime(new Date(), new Locale("es", "ES"));
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With