Java Code Examples for java.time.format.DateTimeFormatter#ISO_DATE
The following examples show how to use
java.time.format.DateTimeFormatter#ISO_DATE .
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: TCKDateTimeFormatter.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Test public void test_parse_CharSequence_ParsePosition_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos); assertEquals(pos.getIndex(), 13); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 2
Source File: TestLocalDateTime.java From code with Apache License 2.0 | 6 votes |
@Test public void test6() { DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE; LocalDateTime ldt = LocalDateTime.now(); String strDate = ldt.format(dtf); System.out.println(strDate); System.out.println("------------------------"); DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");//自定义格式化格式 String strDate2 = dtf2.format(ldt); System.out.println(strDate2);//2017年07月20日 19:49:53 LocalDateTime newDate = ldt.parse(strDate2, dtf2);//以指定格式解析字符串,重新获得LocalDateTime类型 System.out.println(newDate);//2017-07-20T19:49:53 }
Example 3
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Test public void test_parse_CharSequence_ParsePosition_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos); assertEquals(pos.getIndex(), 13); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 4
Source File: TCKDateTimeFormatter.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Test public void test_parse_CharSequence_ParsePosition_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos); assertEquals(pos.getIndex(), 13); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 5
Source File: TCKDateTimeFormatter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_parse_CharSequence_ParsePosition_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos); assertEquals(pos.getIndex(), 13); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 6
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Test public void test_parse_CharSequence_ParsePosition_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos); assertEquals(pos.getIndex(), 13); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 7
Source File: TCKDateTimeFormatter.java From hottub with GNU General Public License v2.0 | 6 votes |
@Test public void test_parse_CharSequence_ParsePosition_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos); assertEquals(pos.getIndex(), 13); assertEquals(pos.getErrorIndex(), -1); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 8
Source File: TCKDateTimeFormatter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_CharSequence_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; TemporalAccessor result = test.parse("2012-06-30"); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 9
Source File: TCKDateTimeFormatter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_CharSequence_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; TemporalAccessor result = test.parse("2012-06-30"); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 10
Source File: TCKDateTimeFormatter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=DateTimeParseException.class) public void test_parse_CharSequence_ParsePosition_parseError() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); try { test.parse("XXX2012XXX", pos); fail(); } catch (DateTimeParseException ex) { assertEquals(ex.getErrorIndex(), 7); throw ex; } }
Example 11
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=DateTimeParseException.class) public void test_parse_CharSequence_ParsePosition_parseError() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); try { test.parse("XXX2012XXX", pos); fail(); } catch (DateTimeParseException ex) { assertEquals(ex.getErrorIndex(), 7); throw ex; } }
Example 12
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=DateTimeParseException.class) public void test_parse_CharSequence_ParsePosition_parseError() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; ParsePosition pos = new ParsePosition(3); try { test.parse("XXX2012XXX", pos); fail(); } catch (DateTimeParseException ex) { assertEquals(ex.getErrorIndex(), 7); throw ex; } }
Example 13
Source File: TCKDateTimeFormatter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_CharSequence_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; TemporalAccessor result = test.parse("2012-06-30"); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 14
Source File: TCKDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_CharSequence_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; TemporalAccessor result = test.parse("2012-06-30"); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 15
Source File: TCKDateTimeFormatter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_CharSequence_resolved() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; TemporalAccessor result = test.parse("2012-06-30"); assertEquals(result.isSupported(YEAR), true); assertEquals(result.isSupported(MONTH_OF_YEAR), true); assertEquals(result.isSupported(DAY_OF_MONTH), true); assertEquals(result.isSupported(HOUR_OF_DAY), false); assertEquals(result.getLong(YEAR), 2012L); assertEquals(result.getLong(MONTH_OF_YEAR), 6L); assertEquals(result.getLong(DAY_OF_MONTH), 30L); assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30)); }
Example 16
Source File: TCKDateTimeFormatter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=IndexOutOfBoundsException.class) public void test_parse_CharSequence_ParsePosition_indexTooBig() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; test.parse("Text", new ParsePosition(5)); }
Example 17
Source File: TCKDateTimeFormatter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=IndexOutOfBoundsException.class) public void test_parse_CharSequence_ParsePosition_indexTooBig() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; test.parse("Text", new ParsePosition(5)); }
Example 18
Source File: TCKDateTimeFormatter.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=IndexOutOfBoundsException.class) public void test_parse_CharSequence_ParsePosition_indexTooBig() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; test.parse("Text", new ParsePosition(5)); }
Example 19
Source File: TCKDateTimeFormatter.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=IndexOutOfBoundsException.class) public void test_parse_CharSequence_ParsePosition_indexTooBig() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; test.parse("Text", new ParsePosition(5)); }
Example 20
Source File: TCKDateTimeFormatter.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=IndexOutOfBoundsException.class) public void test_parse_CharSequence_ParsePosition_indexTooBig() { DateTimeFormatter test = DateTimeFormatter.ISO_DATE; test.parse("Text", new ParsePosition(5)); }