Package org.threeten.bp.format

Examples of org.threeten.bp.format.DateTimeFormatter


        assertEquals(test, MonthDay.of(12, 3));
    }

    @Test(expectedExceptions=NullPointerException.class)
    public void factory_parse_formatter_nullText() {
        DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
        MonthDay.parse((String) null, f);
    }
View Full Code Here


    //-----------------------------------------------------------------------
    // format(DateTimeFormatter)
    //-----------------------------------------------------------------------
    @Test
    public void test_format_formatter() {
        DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
        String t = MonthDay.of(12, 3).format(f);
        assertEquals(t, "12 3");
    }
View Full Code Here

        System.out.println("...resolved to valid date-time in Europe/London: " + resolved);

        String formattedRFC = DateTimeFormatter.RFC_1123_DATE_TIME.format(resolved);
        System.out.println("...printed as RFC1123: " + formattedRFC);

        DateTimeFormatter f = new DateTimeFormatterBuilder()
            .appendValue(YEAR, 4, 10, SignStyle.ALWAYS)
            .appendLiteral(' ')
            .appendText(MONTH_OF_YEAR)
            .appendLiteral('(')
            .appendValue(MONTH_OF_YEAR)
            .appendLiteral(')')
            .appendLiteral(' ')
            .appendValue(DAY_OF_MONTH, 2)
            .toFormatter(Locale.ENGLISH);
        String formatted = f.format(resolved);
        System.out.println("...printed using complex format: " + formatted);

        MonthDay bday = MonthDay.of(DECEMBER, 3);
        System.out.println("Brazillian birthday (no year): " + bday);
    }
View Full Code Here

    //-----------------------------------------------------------------------
    // parse(DateTimeFormatter)
    //-----------------------------------------------------------------------
    @Test
    public void factory_parse_formatter() {
        DateTimeFormatter f = DateTimeFormatter.ofPattern("u");
        Year test = Year.parse("2010", f);
        assertEquals(test, Year.of(2010));
    }
View Full Code Here

        assertEquals(test, Year.of(2010));
    }

    @Test(expectedExceptions=NullPointerException.class)
    public void factory_parse_formatter_nullText() {
        DateTimeFormatter f = DateTimeFormatter.ofPattern("u");
        Year.parse((String) null, f);
    }
View Full Code Here

    //-----------------------------------------------------------------------
    // format(DateTimeFormatter)
    //-----------------------------------------------------------------------
    @Test
    public void test_format_formatter() {
        DateTimeFormatter f = DateTimeFormatter.ofPattern("y");
        String t = Year.of(2010).format(f);
        assertEquals(t, "2010");
    }
View Full Code Here

        LocalDate date3 = LocalDate.now().plus(3, ChronoUnit.DAYS);
        System.out.println("3 days later " + date3);
    }

    private static void print1() {
        DateTimeFormatter f = new DateTimeFormatterBuilder().appendText(ChronoField.AMPM_OF_DAY)
                .appendLiteral(' ').appendValue(ChronoField.AMPM_OF_DAY).toFormatter();
        System.out.println(f.format(LocalTime.of(12, 30)));
        System.out.println(f.format(ZonedDateTime.now()));
    }
View Full Code Here

        System.out.println(f.format(LocalTime.of(12, 30)));
        System.out.println(f.format(ZonedDateTime.now()));
    }

    private static void print2() {
        DateTimeFormatter f = new DateTimeFormatterBuilder().appendText(ChronoField.MONTH_OF_YEAR)
                .appendLiteral(' ').appendValue(ChronoField.YEAR).toFormatter();
        System.out.println(f.format(LocalDate.now()));
        System.out.println(f.format(YearMonth.now()));
        System.out.println(f.format(ZonedDateTime.now()));
    }
View Full Code Here

        result("LocalDT-Q", end - start);
    }

    private static void formatListDateTime(List<LocalDateTime> list) {
        StringBuilder buf = new StringBuilder();
        DateTimeFormatter format = DateTimeFormatter.ISO_DATE.withLocale(Locale.ENGLISH);
        long start = System.nanoTime();
        for (LocalDateTime dt : list) {
            buf.setLength(0);
            buf.append(format.format(dt));
        }
        long end = System.nanoTime();
        System.out.println("LocalDT:   Format: " + NF.format(end - start) + " ns" + " " + buf);
        result("LocalDT-P", end - start);
    }
View Full Code Here

        result("LocalD-Q", end - start);
    }

    private static void formatListLocalDate(List<LocalDate> list) {
        StringBuilder buf = new StringBuilder();
        DateTimeFormatter format = DateTimeFormatter.ISO_DATE.withLocale(Locale.ENGLISH);
        long start = System.nanoTime();
        for (LocalDate dt : list) {
            buf.setLength(0);
            buf.append(format.format(dt));
        }
        long end = System.nanoTime();
        System.out.println("LocalD:    Format: " + NF.format(end - start) + " ns" + " " + buf);
        result("LocalD-P", end - start);
    }
View Full Code Here

TOP

Related Classes of org.threeten.bp.format.DateTimeFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.