本文整理匯總了Java中java.time.format.DateTimeFormatter.withLocale方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTimeFormatter.withLocale方法的具體用法?Java DateTimeFormatter.withLocale怎麽用?Java DateTimeFormatter.withLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.format.DateTimeFormatter
的用法示例。
在下文中一共展示了DateTimeFormatter.withLocale方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLocalDateVariable
import java.time.format.DateTimeFormatter; //導入方法依賴的package包/類
protected LocalDate getLocalDateVariable(String name) {
Integer i = (Integer) facade.getVariable(name);
if (i != null) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
formatter = formatter.withLocale(Locale.FRENCH);
LocalDate date = LocalDate.parse("" + i, formatter);
return date;
}
return null;
}
示例2: test_formatStyle
import java.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test(dataProvider = "formatStyle")
public void test_formatStyle(Temporal temporal, FormatStyle style, String formattedStr) {
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
DateTimeFormatter formatter = builder.appendLocalized(style, style).appendLiteral(" ").appendZoneOrOffsetId().toFormatter();
formatter = formatter.withLocale(Locale.US);
assertEquals(formatter.format(temporal), formattedStr);
}
示例3: test_withLocale_same
import java.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test
public void test_withLocale_same() throws Exception {
DateTimeFormatter base =
new DateTimeFormatterBuilder().appendLiteral("ONE")
.appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE)
.toFormatter(Locale.ENGLISH)
.withDecimalStyle(DecimalStyle.STANDARD);
DateTimeFormatter test = base.withLocale(Locale.ENGLISH);
assertSame(test, base);
}
示例4: test_withLocale
import java.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test
public void test_withLocale() {
DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
DateTimeFormatter test = base.withLocale(Locale.GERMAN);
assertEquals(test.getLocale(), Locale.GERMAN);
}
示例5: test_withLocale_null
import java.time.format.DateTimeFormatter; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void test_withLocale_null() {
DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
base.withLocale((Locale) null);
}
示例6: getFormatter
import java.time.format.DateTimeFormatter; //導入方法依賴的package包/類
/**
* Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
* @param formatter the base formatter that establishes default formatting rules
* (generally user independent)
* @param locale the current user locale (may be {@code null} if not known)
* @return the user-specific DateTimeFormatter
*/
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) {
DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
DateTimeContext context = getDateTimeContext();
return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);
}