I show date ranges as follows:
public static void main(String[] args) {
Locale.setDefault(new Locale("nl", "NL"));
DateTime d1 = new DateTime();
DateTime d2 = new DateTime().plusDays(30);
final String s1 = d1.toString(DateTimeFormat.shortDate());
final String s2 = d2.toString(DateTimeFormat.shortDate());
System.out.println(s1 + "-" + s2); // shows "4/05/12-3/06/12" for en_AU
System.out.println(s1 + "-" + s2); // shows "4-5-12-3-6-12" for nl_NL
}
For users in Holland, they see “4-5-12-3-6-12”. This is confusing.
What’s a way to show date ranges that takes the user’s locale into account?
In a localized application, such separation would be decided by the translators when they translate your resource bundles:
Might become:
This can then be handled using the MessageFormat type. Something of the form:
Even if you’re not providing full translations, this approach might be applicable for certain localizations.