Java DateTimeFormat shortDate无年份
我希望有一个不带年份的Java DateTimeFormat shortDate无年份,java,android,jodatime,Java,Android,Jodatime,我希望有一个不带年份的DateTimeFormat.shortDate(),这样在德语中显示为02.01,在英语中显示为01/02 现在我正在使用下面的方法 return DateTimeFormat.shortDate() .withLocale(Locale.getDefault()) .print(dateTime); 如何避免让日期时间格式打印年份?您的问题已经在这里得到了回答: 至少有一个很好的例子来处理你的问题 另一个选项是,如果您知道您将只支持某些地区,您可以使
DateTimeFormat.shortDate()
,这样在德语中显示为02.01,在英语中显示为01/02
现在我正在使用下面的方法
return DateTimeFormat.shortDate()
.withLocale(Locale.getDefault())
.print(dateTime);
如何避免让
日期时间格式打印年份?您的问题已经在这里得到了回答:
至少有一个很好的例子来处理你的问题
另一个选项是,如果您知道您将只支持某些地区,您可以使用所需的格式制作自己的地图,如:
Map<Locale, DateTimeFormatter> formats = new HashMap<>();
formats.put(Locale.US, DateTimeFormat.forPattern("dd/MM"));
formats.put(Locale.GERMAN, DateTimeFormat.forPattern("MM.dd"));
DateTimeFormatter dateTimeFormatter = Optional.ofNullable(formats.get(Locale.getDefault()))
.orElse(DateTimeFormat.forPattern(DEFAULT_PATTERN));
dateTimeFormatter.print(DateTimeUtils.today());
Map formats=newhashmap();
格式.put(Locale.US,DateTimeFormat.forPattern(“dd/MM”);
格式.put(Locale.derman,DateTimeFormat.forPattern(“MM.dd”);
DateTimeFormatter DateTimeFormatter=Optional.ofNullable(formats.get(Locale.getDefault()))
.orElse(DateTimeFormat.forPattern(默认模式));
dateTimeFormatter.print(DateTimeUtils.today());
您的问题已在此处得到回答:
至少有一个很好的例子来处理你的问题
另一个选项是,如果您知道您将只支持某些地区,您可以使用所需的格式制作自己的地图,如:
Map<Locale, DateTimeFormatter> formats = new HashMap<>();
formats.put(Locale.US, DateTimeFormat.forPattern("dd/MM"));
formats.put(Locale.GERMAN, DateTimeFormat.forPattern("MM.dd"));
DateTimeFormatter dateTimeFormatter = Optional.ofNullable(formats.get(Locale.getDefault()))
.orElse(DateTimeFormat.forPattern(DEFAULT_PATTERN));
dateTimeFormatter.print(DateTimeUtils.today());
Map formats=newhashmap();
格式.put(Locale.US,DateTimeFormat.forPattern(“dd/MM”);
格式.put(Locale.derman,DateTimeFormat.forPattern(“MM.dd”);
DateTimeFormatter DateTimeFormatter=Optional.ofNullable(formats.get(Locale.getDefault()))
.orElse(DateTimeFormat.forPattern(默认模式));
dateTimeFormatter.print(DateTimeUtils.today());
你是说德语02.01和英语01/02是的,对不起。混淆了。抱歉的可能复制在Joda时间内不可能,除非您愿意按照链接复制中的建议进行模式后处理(并非对所有地区都可靠!)。但是,ICU4J和my lib Time4J支持此功能。示例:ChronoFormatter.ofStyle(DisplayMode.SHORT,Locale.getDefault(),AnnualDate.chronology()).format(AnnualDate.from(MonthDay.of(2,28))
您的意思是德语02.01和英语01/02对不起。混淆了。抱歉的可能复制在Joda时间内不可能,除非您愿意按照链接复制中的建议进行模式后处理(并非对所有地区都可靠!)。但是,ICU4J和my lib Time4J支持此功能。示例:ChronoFormatter.ofStyle(DisplayMode.SHORT,Locale.getDefault(),AnnualDate.chronology()).format(AnnualDate.from(MonthDay.of(2,28))
欢迎来到StackOverflow!一旦你有了15个声誉,你就可以将帖子标记为重复。这是在这种情况下要做的事情。您不应该发布包含此类内容的答案:)欢迎使用StackOverflow!一旦你有了15个声誉,你就可以将帖子标记为重复。这是在这种情况下要做的事情。您不应该发布包含此类内容的答案:)