Java-格式日期仅与斜线基于网站

发布于 2025-02-06 16:06:42 字数 439 浏览 3 评论 0原文

我的代码是

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/1306/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聽兲甴掵 2025-02-13 16:06:42

您可以尝试:

DateTimeFormatter pattern = DateTimeFormatter
                .ofPattern("yyyy/MM/dd")
                .withLocale(Locale.forLanguageTag("ja-JP")); // or "en-US"

you can try:

DateTimeFormatter pattern = DateTimeFormatter
                .ofPattern("yyyy/MM/dd")
                .withLocale(Locale.forLanguageTag("ja-JP")); // or "en-US"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文