Example usage for java.time ZonedDateTime parse

List of usage examples for java.time ZonedDateTime parse

Introduction

In this page you can find the example usage for java.time ZonedDateTime parse.

Prototype

public static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter) 

Source Link

Document

Obtains an instance of ZonedDateTime from a text string using a specific formatter.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.parse("2014-09-03T11:38:45.902-07:00[America/Los_Angeles]",
            DateTimeFormatter.ISO_DATE_TIME);

    System.out.println(dateTime);
}

From source file:com.mgmtp.perfload.perfalyzer.util.TestMetadata.java

public static TestMetadata create(final String rawResultsDir, final Properties properties) {
    ZonedDateTime start = ZonedDateTime.parse(properties.getProperty("test.start"),
            DateTimeFormatter.ISO_OFFSET_DATE_TIME);
    ZonedDateTime end = ZonedDateTime.parse(properties.getProperty("test.finish"),
            DateTimeFormatter.ISO_OFFSET_DATE_TIME);
    String duration = DurationFormatUtils.formatDurationHMS(Duration.between(start, end).toMillis());

    String operationsString = properties.getProperty("operations");
    Set<String> operations = newTreeSet(on(',').trimResults().split(operationsString));
    return new TestMetadata(start, end, duration, properties.getProperty("test.file"), rawResultsDir,
            properties.getProperty("perfload.implementation.version"), properties.getProperty("test.comment"),
            operations);/* ww w .j a v a2  s  . com*/
}

From source file:org.commonjava.indy.subsys.prefetch.PrefetchRepoComparator.java

@Override
public int compare(RemoteRepository r1, RemoteRepository r2) {
    if (r1 == null) {
        return 1;
    }//  w  ww .j  a  v a2  s  .c  om
    if (r2 == null) {
        return -1;
    }

    final int priorityCompareResult = r2.getPrefetchPriority() - r1.getPrefetchPriority();
    if (StringUtils.isBlank(r1.getPrefetchRescanTimestamp())
            && StringUtils.isBlank(r2.getPrefetchRescanTimestamp())) {
        return priorityCompareResult;
    }

    if (StringUtils.isBlank(r1.getPrefetchRescanTimestamp())
            && StringUtils.isNotBlank(r2.getPrefetchRescanTimestamp())) {
        return -1;
    } else if (StringUtils.isBlank(r2.getPrefetchRescanTimestamp())
            && StringUtils.isNotBlank(r1.getPrefetchRescanTimestamp())) {
        return 1;
    }

    final ZonedDateTime rescanTime1 = ZonedDateTime.parse(r1.getPrefetchRescanTimestamp(),
            RescanTimeUtils.UTC_TIME_FORMATTER);
    final ZonedDateTime rescanTime2 = ZonedDateTime.parse(r2.getPrefetchRescanTimestamp(),
            RescanTimeUtils.UTC_TIME_FORMATTER);

    if (rescanTime1.isBefore(rescanTime2)) {
        return -1;
    } else if (rescanTime1.isAfter(rescanTime2)) {
        return 1;
    } else {
        return priorityCompareResult;
    }
}

From source file:de.bytefish.fcmjava.client.http.apache.utils.RetryHeaderUtils.java

private static boolean tryToConvertToDate(String dateAsString, OutParameter<ZonedDateTime> result) {
    try {//from   ww w  .ja  va 2  s  .  c  o  m

        // We assume the HTTP Header to contain an RFC1123-compliant DateTime value:
        DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;

        // Try to parse and set it as the result:
        result.set(ZonedDateTime.parse(dateAsString, formatter));

        return true;
    } catch (Exception e) {
        return false;
    }
}

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:ExifUtils.ExifReadWrite.java

private static List<meta> exifToMetaIMR(ArrayList<String> filenames, File dir) {
    List<meta> results = new ArrayList<>();
    for (String filename : filenames) {
        ArrayList<String[]> tags;
        String model = null;//  w w w . jav  a2  s .  c  o  m
        String note = "";
        String iID = null;
        String dID = null;
        String odID = null;
        String captureDate = null;
        Boolean dateFormat = false;
        try {
            tags = readMeta(new File(dir + "\\" + filename));
        } catch (ImageProcessingException | IOException ex) {
            meta meta = new meta(dir + "\\" + filename, getZonedTimeFromStr(captureDate), dateFormat, model,
                    iID, dID, odID, ex.toString());
            System.out.println(meta);
            results.add(meta);
            continue;
        }
        for (String[] tag : tags) {
            //                System.out.println(tag[0]);
            switch (tag[0]) {
            case "Model":
                model = tag[1];
                break;
            case "xmpMM:InstanceID":
                iID = tag[1];
                break;
            case "xmpMM:DocumentID":
                dID = tag[1];
                break;
            case "xmpMM:OriginalDocumentID":
                odID = tag[1];
                break;
            case "Date/Time Original":
                captureDate = tag[1];
                break;
            case "exif:DateTimeOriginal":
                try {
                    ZonedDateTime wTZ = ZonedDateTime.parse(tag[1], XmpDateFormatTZ);
                    if (LocalDateTime.parse(captureDate, ExifDateFormat).equals(wTZ.toLocalDateTime()))
                        dateFormat = true;
                } catch (DateTimeParseException exc) {
                }
                break;
            }
        }
        meta meta = new meta(dir + "\\" + filename, getZonedTimeFromStr(captureDate), dateFormat, model, iID,
                dID, odID, note);
        System.out.println(meta);
        results.add(meta);
    }
    return results;
}

From source file:org.trellisldp.test.MementoResourceTests.java

/**
 * Test the presence of a datetime header for each memento.
 *//* ww w .ja  v  a 2s  .  co  m*/
@Test
@DisplayName("Test the presence of a datetime header for each memento")
default void testMementoDateTimeHeader() {
    getMementos().forEach((memento, date) -> {
        try (final Response res = target(memento).request().get()) {
            assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful memento request");
            final ZonedDateTime zdt = ZonedDateTime.parse(date, RFC_1123_DATE_TIME);
            assertEquals(zdt, ZonedDateTime.parse(res.getHeaderString(MEMENTO_DATETIME), RFC_1123_DATE_TIME),
                    "Check that the memento-datetime header is correct");
        }
    });
}

From source file:sh.scrap.scrapper.functions.DateFunctionFactory.java

private ZonedDateTime parse(String data, String pattern, Locale locale, ZoneId zoneId) {
    DateTimeFormatter format = DateTimeFormatter.ofPattern(pattern, locale).withZone(zoneId);
    return ZonedDateTime.parse(data, format);
}

From source file:org.primeframework.mvc.parameter.convert.converters.ZonedDateTimeConverter.java

private ZonedDateTime toDateTime(String value, String format) {
    try {/*from ww  w  .j a  v  a2  s.  c  om*/
        return ZonedDateTime.parse(value, DateTimeFormatter.ofPattern(format));
    } catch (DateTimeParseException e) {
        throw new ConversionException("Invalid date [" + value + "] for format [" + format + "]", e);
    }
}

From source file:org.trellisldp.test.MementoResourceTests.java

/**
 * Test the presence of a datetime header for each memento.
 *//*from w w  w.j a v a  2  s  . com*/
@Test
@DisplayName("Test the presence of a datetime header for each memento")
default void testMementoAcceptDateTimeHeader() {
    getMementos().forEach((memento, date) -> {
        final String location;
        try (final Response res = target(getResourceLocation()).request().header(ACCEPT_DATETIME, date)
                .head()) {
            if (REDIRECTION.equals(res.getStatusInfo().getFamily())) {
                location = res.getLocation().toString();
            } else {
                assumeTrue(SUCCESSFUL.equals(res.getStatusInfo().getFamily()));
                location = getResourceLocation();
            }
        }

        try (final Response res = target(location).request().header(ACCEPT_DATETIME, date).head()) {
            assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful memento request");
            final ZonedDateTime zdt = ZonedDateTime.parse(date, RFC_1123_DATE_TIME);
            assertEquals(zdt, ZonedDateTime.parse(res.getHeaderString(MEMENTO_DATETIME), RFC_1123_DATE_TIME),
                    "Check that the memento-datetime header is correct");
        }
    });
}