问题描述
我想在 Java 中创建一个没有时间的当前日期的本地化版本,但使用用户的时区。
java.time.format.FormatStyle 有值 - FULL:
Full text style,with the most detail. For example,the format might be 'Tuesday,April 12,1952 AD' or '3:30:42pm PST'.
和长。
Long text style,with lots of detail. For example,the format might be 'January 12,1952'.
我基本上想要两者的混合 - 我只想显示本地化的长日期,例如:1952 年 1 月 12 日 - 但另外,我想添加这个日期的时区, 1952 年 1 月 12 日 PST 或 1952 年 1 月 12 日 MEZ 等。
我试过了:
ZonedDateTime dateTime = zonedDateTime(instant,timezoneId);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(userLocale);
String localizedDate = dateTime.format( dateFormatter.withZone(timezoneId));
但这并没有将时区添加到日期中。当我也打印出时间时,它可以工作,但在这种情况下这不是我想要的。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)