Java Code Examples for java.time.format.DateTimeFormatter#withLocale()
The following examples show how to use
java.time.format.DateTimeFormatter#withLocale() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKFormatStyle.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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); }
Example 2
Source File: TCKFormatStyle.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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); }
Example 3
Source File: TestDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 4
Source File: StrftimeFormatter.java From jinjava with Apache License 2.0 | 5 votes |
public static DateTimeFormatter formatter(String strftime, Locale locale) { DateTimeFormatter fmt; if (strftime == null) { strftime = ""; } switch (strftime.toLowerCase()) { case "short": fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); break; case "medium": fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM); break; case "long": fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG); break; case "full": fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL); break; default: try { fmt = DateTimeFormatter.ofPattern(toJavaDateTimeFormat(strftime)); break; } catch (IllegalArgumentException e) { throw new InvalidDateFormatException(strftime, e); } } return fmt.withLocale(locale); }
Example 5
Source File: TCKFormatStyle.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 6
Source File: TestDateTimeFormatter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@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); }
Example 7
Source File: TestDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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); }
Example 8
Source File: TCKFormatStyle.java From j2objc with Apache License 2.0 | 5 votes |
@Test @UseDataProvider("data_formatStyle") public void test_formatStyle(Temporal temporal, FormatStyle style, String formattedStr) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeFormatter formatter = builder.appendLocalized(style, style).appendLiteral(" ").appendZoneOrOffsetId().toFormatter(); // Android-changed: Use a locale that actually uses "CEST" as short form of Europe/Paris. formatter = formatter.withLocale(Locale.UK); assertEquals(formatter.format(temporal), formattedStr); }
Example 9
Source File: TCKFormatStyle.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@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); }
Example 10
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@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); }
Example 11
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void test_withLocale_null() { DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD); base.withLocale((Locale) null); }
Example 12
Source File: TCKDateTimeFormatter.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void test_withLocale_null() { DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD); base.withLocale((Locale) null); }
Example 13
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void test_withLocale_null() { DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD); base.withLocale((Locale) null); }
Example 14
Source File: TCKDateTimeFormatter.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@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); }
Example 15
Source File: TCKDateTimeFormatter.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void test_withLocale_null() { DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD); base.withLocale((Locale) null); }
Example 16
Source File: TCKDateTimeFormatter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@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); }
Example 17
Source File: DateTimeFormatterFactoryTests.java From spring-analysis-note with MIT License | 4 votes |
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) { return dateTimeFormatter.withLocale(Locale.US); }
Example 18
Source File: DateTimeContextHolder.java From spring-analysis-note with MIT License | 3 votes |
/** * 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, @Nullable Locale locale) { DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter); DateTimeContext context = getDateTimeContext(); return (context != null ? context.getFormatter(formatterToUse) : formatterToUse); }
Example 19
Source File: DateTimeContextHolder.java From java-technology-stack with MIT License | 2 votes |
/** * 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, @Nullable Locale locale) { DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter); DateTimeContext context = getDateTimeContext(); return (context != null ? context.getFormatter(formatterToUse) : formatterToUse); }
Example 20
Source File: DateTimeContextHolder.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * 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); }