Example usage for java.time LocalDateTime parse

List of usage examples for java.time LocalDateTime parse

Introduction

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

Prototype

public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) 

Source Link

Document

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

Usage

From source file:net.tourbook.photo.Photo.java

/**
 * Date/Time// w ww. j av a 2s.com
 * 
 * @param jpegMetadata
 * @param file
 * @return
 */
private LocalDateTime getExifValueDate(final JpegImageMetadata jpegMetadata) {

    //      /*
    //       * !!! time is not correct, maybe it is the time when the GPS signal was
    //       * received !!!
    //       */
    //      printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_TIME_STAMP);

    try {

        final TiffField exifDate = jpegMetadata.findEXIFValueWithExactMatch(//
                ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);

        if (exifDate != null) {
            return LocalDateTime.parse(exifDate.getStringValue(), _dtParser);
        }

        final TiffField tiffDate = jpegMetadata
                .findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_DATE_TIME);

        if (tiffDate != null) {
            return LocalDateTime.parse(tiffDate.getStringValue(), _dtParser);
        }

    } catch (final Exception e) {
        // ignore
    }

    return null;
}

From source file:com.tascape.reactor.report.MySqlBaseBean.java

public static long getMillis(String time) {
    if (time == null || time.trim().isEmpty()) {
        return System.currentTimeMillis();
    } else {/*from w ww.  ja  v  a  2  s  .co m*/
        LocalDateTime ldt = LocalDateTime.parse(time, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        LOG.trace("ldt {}", ldt);
        ZoneId zone = ZoneId.of("America/Los_Angeles");
        ldt.atZone(zone);
        LOG.trace("ldt {}", ldt);
        return ldt.toInstant(ZoneOffset.ofHours(-8)).toEpochMilli();
    }
}

From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java

/**
 * Gets a list of all the posted ballots of the given election form the bulletin board and returns it
 * @param election// ww  w . ja v a  2 s.c o m
 * Election for which the list of ballots should be retrieved 
 * @return 
 * the list of all posted ballots to the given election
 */
public List<Ballot> getBallotsByElection(Election election) {
    List<Ballot> ballots = new ArrayList<Ballot>();
    try {

        URL url = new URL(bulletinBoardUrl + "/elections/" + election.getId() + "/ballots");

        InputStream urlInputStream = url.openStream();
        JsonReader jsonReader = Json.createReader(urlInputStream);
        JsonArray obj = jsonReader.readArray();
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //transforms the recieved json string into a list of ballot objects
        for (JsonObject result : obj.getValuesAs(JsonObject.class)) {

            int id = Integer.parseInt(result.getString("id"));
            LocalDateTime timeStamp = LocalDateTime.parse(result.getString("timestamp"), format);

            JsonObject jsonData = result.getJsonObject("jsonData");
            List<String> selectedOptions = new ArrayList<String>();
            JsonArray optionsArray = jsonData.getJsonArray("e");
            for (int i = 0; i < optionsArray.size(); i++) {
                selectedOptions.add(optionsArray.getString(i));
            }
            String u_HatString = jsonData.getString("u_Hat");
            String cString = jsonData.getString("c");
            String dString = jsonData.getString("d");
            String pi1String = jsonData.getString("pi1");
            String pi2String = jsonData.getString("pi2");
            String pi3String = jsonData.getString("pi3");
            //create ballot object and add it to the list
            Ballot ballot = new Ballot(id, election, selectedOptions, u_HatString, cString, dString, pi1String,
                    pi2String, pi3String, timeStamp);
            System.out.println(ballot.isValid());
            ballots.add(ballot);
        }

    } catch (IOException x) {
        System.err.println(x);
    }
    return ballots;

}

From source file:com.streamsets.pipeline.stage.origin.jdbc.cdc.oracle.OracleCDCSource.java

private void startGeneratorThread(String lastSourceOffset) throws StageException, SQLException {
    Offset offset = null;/*  w w  w.  ja  va 2s  .c  o m*/
    LocalDateTime startTimestamp;
    try {
        startLogMnrForRedoDict();
        if (!StringUtils.isEmpty(lastSourceOffset)) {
            offset = new Offset(lastSourceOffset);
            if (lastSourceOffset.startsWith("v3")) {
                if (!useLocalBuffering) {
                    throw new StageException(JDBC_82);
                }
                startTimestamp = offset.timestamp.minusSeconds(configBean.txnWindow);
            } else {
                if (useLocalBuffering) {
                    throw new StageException(JDBC_83);
                }
                startTimestamp = getDateForSCN(new BigDecimal(offset.scn));
            }
            offset.timestamp = startTimestamp;
            adjustStartTimeAndStartLogMnr(startTimestamp);
        } else { // reset the start date only if it not set.
            if (configBean.startValue != StartValues.SCN) {
                LocalDateTime startDate;
                if (configBean.startValue == StartValues.DATE) {
                    startDate = LocalDateTime.parse(configBean.startDate, dateTimeColumnHandler.dateFormatter);
                } else {
                    startDate = nowAtDBTz();
                }
                startDate = adjustStartTimeAndStartLogMnr(startDate);
                offset = new Offset(version, startDate, ZERO, 0, "");
            } else {
                BigDecimal startCommitSCN = new BigDecimal(configBean.startSCN);
                startLogMnrSCNToDate.setBigDecimal(1, startCommitSCN);
                final LocalDateTime start = getDateForSCN(startCommitSCN);
                LocalDateTime endTime = getEndTimeForStartTime(start);
                startLogMnrSCNToDate.setString(2, endTime.format(dateTimeColumnHandler.dateFormatter));
                startLogMnrSCNToDate.execute();
                offset = new Offset(version, start, startCommitSCN.toPlainString(), 0, "");
            }
        }
    } catch (SQLException ex) {
        LOG.error("SQLException while trying to setup record generator thread", ex);
        generationStarted = false;
        throw new StageException(JDBC_52, ex);
    }
    final Offset os = offset;
    final PreparedStatement select = selectFromLogMnrContents;
    generationExecutor.submit(() -> {
        try {
            generateRecords(os, select);
        } catch (Throwable ex) {
            LOG.error("Error while producing records", ex);
            generationStarted = false;
        }
    });
}

From source file:org.apache.drill.test.TestBuilder.java

/**
 * Helper method for the timestamp values that depend on the local timezone
 * @param value expected timestamp value in UTC
 * @return LocalDateTime value for the local timezone
 *//* w ww .j  av  a2 s  .  c om*/
public static LocalDateTime convertToLocalDateTime(String value) {
    OffsetDateTime utcDateTime = LocalDateTime.parse(value, DateUtility.getDateTimeFormatter())
            .atOffset(ZoneOffset.UTC);
    return utcDateTime.atZoneSameInstant(ZoneOffset.systemDefault()).toLocalDateTime();
}

From source file:net.tourbook.photo.Photo.java

private LocalDateTime getTiffValueDate(final TiffImageMetadata tiffMetadata) {

    try {//from   w  w  w . j  a  v a 2 s  . co  m

        final TiffField exifDate = tiffMetadata.findField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, true);

        if (exifDate != null) {
            return LocalDateTime.parse(exifDate.getStringValue(), _dtParser);
        }

        final TiffField date = tiffMetadata.findField(TiffTagConstants.TIFF_TAG_DATE_TIME, true);
        if (date != null) {
            return LocalDateTime.parse(date.getStringValue(), _dtParser);
        }

    } catch (final Exception e) {
        // ignore
    }

    return null;
}

From source file:org.kitodo.production.services.data.ProcessService.java

/**
 * Calculate and return duration/age of given process as a String.
 *
 * @param process ProcessDTO object for which duration/age is calculated
 * @return process age of given process//  w w  w.  j  a  v a2  s.c  om
 */
public static String getProcessDuration(ProcessDTO process) {
    String creationDateTimeString = process.getCreationDate();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    LocalDateTime createLocalDate = LocalDateTime.parse(creationDateTimeString, formatter);
    Duration duration = Duration.between(createLocalDate, LocalDateTime.now());
    return String.format("%sd; %sh", duration.toDays(),
            duration.toHours() - TimeUnit.DAYS.toHours(duration.toDays()));
}