Java-格式日期仅与斜线基于网站
我的代码是
ZonedDateTime zoned = ZonedDateTime.now();
DateTimeFormatter pattern = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(Locale.forLanguageTag("ja-JP"));
System.out.println(zoned.format(pattern));
,输出是2022/06/13
,这很好。但是,当我将语言环境更改为en-us
时,日期为2022年6月13日
。我想拥有所有基于语言环境的日期,只能有数字和砍伐,例如2022/06/13
,06/13/2022
。我该怎么做?
My code is
ZonedDateTime zoned = ZonedDateTime.now();
DateTimeFormatter pattern = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(Locale.forLanguageTag("ja-JP"));
System.out.println(zoned.format(pattern));
And the output is 2022/06/13
, which is fine. But when I change the locale to en-US
, the date is Jun 13, 2022
. I want to have all locale-based date to only have numbers and slashes, like 2022/06/13
, 06/13/2022
. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试:
you can try: