久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 java.time 中從 `DateTimeFormatter.ofLocalized...` 生成的

Force 4-digit-year in localized strings generated from `DateTimeFormatter.ofLocalized…` in java.time(在 java.time 中從 `DateTimeFormatter.ofLocalized...` 生成的本地化字符串中強(qiáng)制使用 4 位數(shù)年份) - IT屋-程序員軟件開
本文介紹了在 java.time 中從 `DateTimeFormatter.ofLocalized...` 生成的本地化字符串中強(qiáng)制使用 4 位數(shù)年份的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號..

DateTimeFormatter java.time 中的類提供了三個(gè) ofLocalized… 方法來生成字符串來表示包含年份的值.例如,ofLocalizedDate.

The DateTimeFormatter class in java.time offers three ofLocalized… methods for generating strings to represent values that include a year. For example, ofLocalizedDate.

Locale l = Locale.US ; 
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate( FormatStyle.SHORT ).withLocale( l );
LocalDate today = LocalDate.now( ZoneId.of( "America/Chicago" ) );
String output = today.format( f );

對于我所看到的語言環(huán)境,年份只有兩位數(shù),較短的 FormatStyle 樣式.

For the locales I have seen, the year is only two digits in the shorter FormatStyle styles.

如何讓 java.time 本地化強(qiáng)制年份為四位數(shù)而不是兩位?

How to let java.time localize yet force the years to be four digits rather than two?

我懷疑答案在于 DateTimeFormatterBuilder 類.但我找不到任何改變年份長度的功能.我還仔細(xì)閱讀了 Java 9 源代碼,但無法很好地挖掘該代碼以找到答案.

I suspect the Answer lies in DateTimeFormatterBuilder class. But I cannot find any feature alter the length of year. I also perused the Java 9 source code, but cannot spelunk that code well enough to find an answer.

這個(gè)問題類似于:

  • 在 java 的 simpledateformat 中強(qiáng)制使用 4 位數(shù)年份
  • Jodatime:如何打印 4 位數(shù)年份?

...但是這些問題針對的是現(xiàn)在被 java.time 類取代的舊日期時(shí)間框架.

…but those Questions are aimed at older date-time frameworks now supplanted by the java.time classes.

推薦答案

沒有你想要的內(nèi)置方法.但是,您可以應(yīng)用以下解決方法:

There is no built-in method for what you want. However, you could apply following workaround:

Locale locale = Locale.ENGLISH;
String shortPattern =
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(
        FormatStyle.SHORT,
        null,
        IsoChronology.INSTANCE,
        locale
    );
System.out.println(shortPattern); // M/d/yy
if (shortPattern.contains("yy") && !shortPattern.contains("yyy")) {
    shortPattern = shortPattern.replace("yy", "yyyy");
}
System.out.println(shortPattern); // M/d/yyyy

DateTimeFormatter shortStyleFormatter = DateTimeFormatter.ofPattern(shortPattern, locale);
LocalDate today = LocalDate.now(ZoneId.of("America/Chicago"));
String output = today.format(shortStyleFormatter);
System.out.println(output); // 11/29/2016

這篇關(guān)于在 java.time 中從 `DateTimeFormatter.ofLocalized...` 生成的本地化字符串中強(qiáng)制使用 4 位數(shù)年份的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 国产欧美一区二区三区另类精品 | 天堂资源最新在线 | 国产午夜在线观看 | 精品1区2区3区4区 | 蜜桃毛片| 欧美簧片 | 日韩一区二区三区在线 | 成人精品一区亚洲午夜久久久 | 国产精品一区二区三区四区 | 欧美激情视频一区二区三区免费 | 色婷婷综合久久久久中文一区二区 | 午夜av成人 | 久久精品国产亚洲一区二区三区 | 高清成人免费视频 | 国产黄色免费网站 | 国产亚洲精品91 | 成人av网站在线观看 | 精品国产一区久久 | 亚洲毛片| 亚洲韩国精品 | 久久新视频 | 亚洲视频免费在线观看 | 成人在线视频网 | 秋霞国产| 国产精品观看 | 欧美福利 | 99精品欧美一区二区蜜桃免费 | 免费精品 | 精品国产乱码久久久久久蜜臀 | 极品的亚洲 | 亚洲成人福利视频 | 久久草在线视频 | www.av在线| 久久网站免费视频 | 一区二区不卡高清 | 国产精品一区在线 | 亚洲精品久久久一区二区三区 | 国产精品久久久久久久久久妞妞 | 男女视频在线观看网站 | 国户精品久久久久久久久久久不卡 | 国产福利资源 |