Example usage for java.time.format DateTimeFormatter ISO_ZONED_DATE_TIME

List of usage examples for java.time.format DateTimeFormatter ISO_ZONED_DATE_TIME

Introduction

In this page you can find the example usage for java.time.format DateTimeFormatter ISO_ZONED_DATE_TIME.

Prototype

DateTimeFormatter ISO_ZONED_DATE_TIME

To view the source code for java.time.format DateTimeFormatter ISO_ZONED_DATE_TIME.

Click Source Link

Document

The ISO-like date-time formatter that formats or parses a date-time with offset and zone, such as '2011-12-03T10:15:30+01:00[Europe/Paris]'.

Usage

From source file:com.streamsets.datacollector.json.TestJsonRecordWriterImpl.java

@Test
public void testZonedDateTime() throws Exception {
    ZonedDateTime now = ZonedDateTime.now();
    StringWriter writer = new StringWriter();
    JsonRecordWriterImpl jsonRecordWriter = new JsonRecordWriterImpl(writer, Mode.MULTIPLE_OBJECTS);

    Record record = new RecordImpl("stage", "id", null, null);
    record.set(Field.createZonedDateTime(now));
    jsonRecordWriter.write(record);//from  w w w .j a  va 2  s .co  m
    jsonRecordWriter.close();

    Assert.assertEquals("\"" + now.format(DateTimeFormatter.ISO_ZONED_DATE_TIME) + "\"", writer.toString());
}

From source file:alfio.util.TemplateManager.java

@Autowired
public TemplateManager(JMustacheTemplateLoader templateLoader, MessageSource messageSource,
        UploadedResourceManager uploadedResourceManager) {
    this.messageSource = messageSource;
    this.uploadedResourceManager = uploadedResourceManager;
    Formatter dateFormatter = (o) -> {
        return (o instanceof ZonedDateTime) ? DateTimeFormatter.ISO_ZONED_DATE_TIME.format((ZonedDateTime) o)
                : String.valueOf(o);
    };//from ww  w.ja v  a2  s . c o m
    this.compilers = new EnumMap<>(TemplateOutput.class);
    this.compilers.put(TemplateOutput.TEXT, Mustache.compiler().escapeHTML(false).standardsMode(false)
            .defaultValue("").nullValue("").withFormatter(dateFormatter).withLoader(templateLoader));
    this.compilers.put(TemplateOutput.HTML, Mustache.compiler().escapeHTML(true).standardsMode(false)
            .defaultValue("").nullValue("").withFormatter(dateFormatter).withLoader(templateLoader));
}

From source file:lumbermill.api.JsonEvent.java

public ZonedDateTime timestamp(String field) {
    return ZonedDateTime.parse(valueAsString(field), DateTimeFormatter.ISO_ZONED_DATE_TIME);
}

From source file:alfio.config.MvcConfiguration.java

@Bean
public JMustacheTemplateFactory getTemplateFactory() throws Exception {
    final JMustacheTemplateFactory templateFactory = new JMustacheTemplateFactory();

    templateFactory.setPrefix("/WEB-INF/templates");
    templateFactory.setSuffix(".ms");
    templateFactory.setTemplateLoader(templateLoader);
    templateFactory.setCompiler(Mustache.compiler().escapeHTML(true).standardsMode(false).defaultValue("")
            .nullValue("").withFormatter((o) -> {
                if (o instanceof ZonedDateTime) {
                    return DateTimeFormatter.ISO_ZONED_DATE_TIME.format((ZonedDateTime) o);
                } else if (o instanceof DefaultMessageSourceResolvable) {
                    DefaultMessageSourceResolvable m = ((DefaultMessageSourceResolvable) o);
                    return m.getCode() + " "
                            + Arrays.stream(Optional.ofNullable(m.getArguments()).orElse(new Object[] {}))
                                    .map(x -> "[" + x.toString() + "]").collect(Collectors.joining(" "));
                } else {
                    return String.valueOf(o);
                }//from w  w  w  . j av a  2s .  c  o m
            }).withLoader(templateLoader));

    templateFactory.afterPropertiesSet();
    return templateFactory;
}

From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java

@SuppressWarnings("unused")
private static void validateISOPattens(List<String> isoPatternList) {

    Set<String> formattedDateTimeSet = new HashSet<String>();
    for (String pattern : isoPatternList) {
        formattedDateTimeSet.add(getFormattedDateTime(pattern, Locale.US));
    }//from   w w  w. j  ava 2 s  .c  o  m

    DateTimeFormatter[] formatters = new DateTimeFormatter[] { DateTimeFormatter.BASIC_ISO_DATE, // 1
            DateTimeFormatter.ISO_DATE, // 2
            DateTimeFormatter.ISO_DATE_TIME, // 3
            // DateTimeFormatter.ISO_TIME, //
            DateTimeFormatter.ISO_INSTANT, // 4
            DateTimeFormatter.ISO_LOCAL_DATE, // 5
            DateTimeFormatter.ISO_LOCAL_DATE_TIME, // 6
            // DateTimeFormatter.ISO_LOCAL_TIME, //
            DateTimeFormatter.ISO_OFFSET_DATE, // 7
            DateTimeFormatter.ISO_OFFSET_DATE_TIME, // 8
            // DateTimeFormatter.ISO_OFFSET_TIME, //
            DateTimeFormatter.ISO_ORDINAL_DATE, // 9
            DateTimeFormatter.ISO_WEEK_DATE, // 10
            DateTimeFormatter.ISO_ZONED_DATE_TIME, // 11
            DateTimeFormatter.RFC_1123_DATE_TIME, // 12
    };

    System.out.println("-------------Validate ISO PattenText-------------");
    for (int i = 0; i < formatters.length; i++) {

        System.out.print((i + 1) + "\t");
        try {
            String formattedDateTime = ZONED_DATE_TIME.format(formatters[i]);
            System.out.print(formattedDateTimeSet.contains(formattedDateTime) ? "YES\t" : "NO\t");
            System.out.println(formattedDateTime);
        } catch (Throwable t) {
            System.out.println(t.getMessage());
        }
    }

}