Java Code Examples for java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME

The following examples show how to use java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME . 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: JdbcCommon.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static DateTimeFormatter getDateTimeFormatter(String pattern) {
    switch(pattern) {
        case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE;
        case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE;
        case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE;
        case "ISO_DATE": return DateTimeFormatter.ISO_DATE;
        case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME;
        case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME;
        case "ISO_TIME": return DateTimeFormatter.ISO_TIME;
        case "ISO_LOCAL_DATE_TIME": return DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        case "ISO_OFFSET_DATE_TIME": return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
        case "ISO_ZONED_DATE_TIME": return DateTimeFormatter.ISO_ZONED_DATE_TIME;
        case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME;
        case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE;
        case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE;
        case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT;
        case "RFC_1123_DATE_TIME": return DateTimeFormatter.RFC_1123_DATE_TIME;
        default: return DateTimeFormatter.ofPattern(pattern);
    }
}
 
Example 2
Source File: TestSyslogDecoder.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void testRfc5424DateParsing() throws Exception {
  final String[] examples = {
      "1985-04-12T23:20:50.52Z",
      "1985-04-12T19:20:50.52-04:00",
      "2003-10-11T22:14:15.003Z",
      "2003-08-24T05:14:15.000003-07:00",
      "2012-04-13T11:11:11-08:00",
      "2012-04-13T08:08:08.0001+00:00",
      "2012-04-13T08:08:08.251+00:00"
  };
  SyslogDecoder decoder = new SyslogDecoder(StandardCharsets.UTF_8, getSystemClock());
  DateTimeFormatter parser = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
  for (String example : examples) {
    assertEquals(
        "Problem parsing date string: " + example, OffsetDateTime.parse(example, parser).toInstant().toEpochMilli(),
        decoder.parseRfc5424Date(example)
    );
  }
}
 
Example 3
Source File: PutSQL.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private DateTimeFormatter getDateTimeFormatter(String pattern) {
    switch(pattern) {
        case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE;
        case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE;
        case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE;
        case "ISO_DATE": return DateTimeFormatter.ISO_DATE;
        case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME;
        case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME;
        case "ISO_TIME": return DateTimeFormatter.ISO_TIME;
        case "ISO_LOCAL_DATE_TIME": return DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        case "ISO_OFFSET_DATE_TIME": return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
        case "ISO_ZONED_DATE_TIME": return DateTimeFormatter.ISO_ZONED_DATE_TIME;
        case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME;
        case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE;
        case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE;
        case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT;
        case "RFC_1123_DATE_TIME": return DateTimeFormatter.RFC_1123_DATE_TIME;
        default: return DateTimeFormatter.ofPattern(pattern);
    }
}
 
Example 4
Source File: HgRepository.java    From skara with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Hash commit(String message, String authorName, String authorEmail, ZonedDateTime authorDate)  throws IOException {
    var user = authorEmail == null ? authorName : authorName + " <" + authorEmail + ">";
    var cmd = new ArrayList<String>();
    cmd.addAll(List.of("hg", "commit", "--message=" + message, "--user=" + user));
    if (authorDate != null) {
        var formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
        cmd.add("--date=" + authorDate.format(formatter));
    }
    try (var p = capture(cmd)) {
        await(p);
    }
    return resolve("tip").orElseThrow(() -> new IOException("Could not resolve 'tip'"));
}
 
Example 5
Source File: JsonEventFormatter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates the {@link JsonEventFormatter}.
 *
 * @return the newly created formatter
 */
public JsonEventFormatter build() {
    final Map<String, Object> metaData = (this.metaData == null ? Collections.emptyMap() : new LinkedHashMap<>(this.metaData));
    final String timestampKey = (this.timestampKey == null ? "timestamp" : this.timestampKey);
    final DateTimeFormatter formatter = (this.formatter == null ? DateTimeFormatter.ISO_OFFSET_DATE_TIME : this.formatter);
    final ZoneId zoneId = (this.zoneId == null ? ZoneId.systemDefault() : this.zoneId);
    return new JsonEventFormatter(metaData, timestampKey, formatter.withZone(zoneId), includeTimestamp);
}
 
Example 6
Source File: JSONTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultDate() throws Exception {
    final DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    final String dateStr = "2015-11-07T14:11:05.267Z";
    order.setShipDate(dateFormat.parse(dateStr, OffsetDateTime::from));

    String str = json.getContext(null).writeValueAsString(order);
    Order o = json.getContext(null).readValue(str, Order.class);
    assertEquals(dateStr, dateFormat.format(o.getShipDate()));
}
 
Example 7
Source File: JSONTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultDate() throws Exception {
    final DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    final String dateStr = "2015-11-07T14:11:05.267Z";
    order.setShipDate(dateFormat.parse(dateStr, OffsetDateTime::from));

    String str = json.getContext(null).writeValueAsString(order);
    Order o = json.getContext(null).readValue(str, Order.class);
    assertEquals(dateStr, dateFormat.format(o.getShipDate()));
}
 
Example 8
Source File: Iso.java    From cactoos with MIT License 4 votes vote down vote up
@Override
public DateTimeFormatter value() {
    return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
}
 
Example 9
Source File: TCKDTFParsedInstant.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="parseWithOffsetWithoutZone")
public void testWithOffsetWithoutZone(String odtString, OffsetDateTime expectedOTD) {
    dtFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    odt1 = OffsetDateTime.parse(odtString, dtFormatter);
    assertEquals(expectedOTD, odt1);
}
 
Example 10
Source File: OffsetDateTimeSerializer.java    From jackson-modules-java8 with Apache License 2.0 4 votes vote down vote up
protected OffsetDateTimeSerializer() {
    super(OffsetDateTime.class, dt -> dt.toInstant().toEpochMilli(),
            OffsetDateTime::toEpochSecond, OffsetDateTime::getNano,
            DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
 
Example 11
Source File: ZonedDateTimeSerializer.java    From jackson-modules-java8 with Apache License 2.0 4 votes vote down vote up
protected ZonedDateTimeSerializer() {
    // ISO_ZONED_DATE_TIME is not the ISO format, it is an extension of it
    this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
 
Example 12
Source File: JSON.java    From eve-esi with Apache License 2.0 4 votes vote down vote up
public OffsetDateTimeTypeAdapter() {
    this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
 
Example 13
Source File: OffsetDateTimeXmlAdapter.java    From threeten-jaxb with Apache License 2.0 4 votes vote down vote up
public OffsetDateTimeXmlAdapter() {
    super(DateTimeFormatter.ISO_OFFSET_DATE_TIME, OffsetDateTime::from);
}
 
Example 14
Source File: DateTimeFormatters.java    From agrest with Apache License 2.0 4 votes vote down vote up
public static DateTimeFormatter isoOffsetDateTime() {
    return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
}
 
Example 15
Source File: JSON.java    From influxdb-client-java with MIT License 4 votes vote down vote up
public OffsetDateTimeTypeAdapter() {
    this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
 
Example 16
Source File: JavaTimeTypesParamConverterProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected DateTimeFormatter getFormatter() {
    return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
}
 
Example 17
Source File: JsonUtils.java    From CertificateDownloader with MIT License 4 votes vote down vote up
public OffsetDateTimeTypeAdapter() {
    this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}