本文整理汇总了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);
}