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) 

Source Link

Document

Obtains an instance of ZonedDateTime from a text string such as 2007-12-03T10:15:30+01:00[Europe/Paris] .

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.parse("2007-12-03T10:15:30+01:00[Europe/Paris]");
    System.out.println(dateTime);
}

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]");

    System.out.println(dateTime);
}

From source file:ch.rasc.wampspring.demo.various.scheduler.LocalDateTimeDeserializer.java

@Override
public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    if (jp.getText().contains("+") || jp.getText().endsWith("Z")) {
        return ZonedDateTime.parse(jp.getText()).toLocalDateTime();
    }//from  w ww.j a v  a2 s.  co m
    return LocalDateTime.parse(jp.getText());
}

From source file:net.javacrumbs.codecamp.boot.common.CsvFileLogger.java

private static Message parseRecord(CSVRecord record) {
    return new Message(Message.Severity.valueOf(record.get(0)), record.get(1),
            ZonedDateTime.parse(record.get(2)));
}

From source file:com.github.ibm.domino.resource.EventTime.java

public ZonedDateTime getEventDateTime() {

    String timeZone;// w w  w  . ja v  a  2 s .c om
    if (isUtc()) {
        timeZone = "Z";
    } else {
        timeZone = "";
    }
    if (geteTime() == null) {
        return LocalDate.parse(geteDate()).atStartOfDay(ZoneId.systemDefault());
    } else {
        return ZonedDateTime.parse(geteDate() + "T" + geteTime() + timeZone);
    }
}

From source file:com.mgmtp.perfload.perfalyzer.normalization.PerfMonNormalizingStrategy.java

@Override
public List<ChannelData> normalizeLine(final String line) {
    tokenizer.reset(line);//from  ww w. j a  v  a 2 s.  c  o  m
    List<String> tokenList = tokenizer.getTokenList();

    List<ChannelData> result = newArrayListWithExpectedSize(3);
    ZonedDateTime timestamp;
    try {
        timestamp = ZonedDateTime.parse(tokenList.get(0));
    } catch (IllegalArgumentException ex) {
        log.error("Invalid data line: {}", line);
        return result;
    }

    if (!timestampNormalizer.isInRange(timestamp)) {
        log.trace("Skipping perfMon entry. Timestamp not in time range of test: " + timestamp);
        return result;
    }

    String type = tokenList.get(1);

    for (PerfMonTypeConfig typeConfig : PerfMonTypeConfig.values()) {
        Matcher matcher = typeConfig.getPattern().matcher(type);

        if (matcher.matches()) {
            if (typeConfig.isNormalizeValues()) {
                if (firstValues == null) {
                    firstValues = newHashMapWithExpectedSize(3);
                }
            }

            for (ValueHolder vh : selectValues(typeConfig, tokenList)) {
                String channelKey = type;
                if (vh.descriptor != null) {
                    channelKey += "_" + vh.descriptor;
                }
                long normalizedTimestamp = timestampNormalizer.normalizeTimestamp(timestamp, 0L);

                try {
                    // normalize against first value
                    double value = typeConfig.factor(Double.parseDouble(vh.value));
                    if (typeConfig.isNormalizeValues()) {
                        Double firstValue = firstValues.get(channelKey);
                        if (firstValue == null) {
                            firstValues.put(channelKey, value);
                            value = 0d;
                        } else {
                            value = value - firstValue;
                        }
                    }

                    StrBuilder sb = new StrBuilder();
                    appendEscapedAndQuoted(sb, DELIMITER, normalizedTimestamp);
                    appendEscapedAndQuoted(sb, DELIMITER, channelKey);
                    appendEscapedAndQuoted(sb, DELIMITER, value);

                    String resultLine = sb.toString();
                    result.add(new ChannelData(CHANNEL_BASE_NAME, channelKey, resultLine));
                } catch (NumberFormatException ex) {
                    // in case a line in the perfmon file is incomplete
                    log.warn("Could not parse line: " + line, ex);
                }
            }
            break;
        }
    }

    return result;
}

From source file:eu.over9000.skadi.ui.dialogs.UpdateAvailableDialog.java

public UpdateAvailableDialog(RemoteVersionResult newVersion) {
    super(AlertType.INFORMATION, null, UPDATE_BUTTON_TYPE, IGNORE_BUTTON_TYPE);

    this.setTitle("Update available");
    this.setHeaderText(newVersion.getVersion() + " is available");

    Label lbChangeLog = new Label("Changelog:");
    TextArea taChangeLog = new TextArea(newVersion.getChangeLog());
    taChangeLog.setEditable(false);//from www.  j  a va  2  s. c  om
    taChangeLog.setWrapText(true);

    Label lbSize = new Label("Size:");
    Label lbSizeValue = new Label(FileUtils.byteCountToDisplaySize(newVersion.getSize()));

    Label lbPublished = new Label("Published");
    Label lbPublishedValue = new Label(
            ZonedDateTime.parse(newVersion.getPublished()).format(DateTimeFormatter.RFC_1123_DATE_TIME));

    final GridPane grid = new GridPane();
    RowConstraints vAlign = new RowConstraints();
    vAlign.setValignment(VPos.TOP);
    grid.getRowConstraints().add(vAlign);
    grid.setHgap(10);
    grid.setVgap(10);

    grid.add(lbChangeLog, 0, 0);
    grid.add(taChangeLog, 1, 0);
    grid.add(lbPublished, 0, 1);
    grid.add(lbPublishedValue, 1, 1);
    grid.add(lbSize, 0, 2);
    grid.add(lbSizeValue, 1, 2);

    this.getDialogPane().setContent(grid);
}

From source file:io.gravitee.repository.elasticsearch.monitoring.ElasticMonitoringRepository.java

@SuppressWarnings("unchecked")
private MonitoringResponse convert(final Map<String, Object> source) {
    final MonitoringResponse monitoringResponse = new MonitoringResponse();
    monitoringResponse.setGatewayId((String) source.get(FIELD_GATEWAY_NAME));
    monitoringResponse.setTimestamp(ZonedDateTime.parse((String) source.get(FIELD_TIMESTAMP)));
    monitoringResponse.setHostname((String) source.get(FIELD_HOSTNAME));

    // OS/*from www  .  ja v  a  2 s .c  om*/

    final Map<String, Object> os = (Map<String, Object>) source.get(FIELD_OS);

    final Map<String, Object> cpu = (Map<String, Object>) os.get("cpu");
    monitoringResponse.setOsCPUPercent((Integer) cpu.get("percent"));
    monitoringResponse.setOsCPULoadAverage((Map<String, Double>) cpu.get("load_average"));

    final Map<String, Object> osMem = (Map<String, Object>) os.get("mem");
    monitoringResponse.setOsMemUsedInBytes(getLongValue(osMem.get("used_in_bytes")));
    monitoringResponse.setOsMemFreeInBytes(getLongValue(osMem.get("free_in_bytes")));
    monitoringResponse.setOsMemTotalInBytes(getLongValue(osMem.get("total_in_bytes")));
    monitoringResponse.setOsMemUsedPercent((Integer) osMem.get("used_percent"));
    monitoringResponse.setOsMemFreePercent((Integer) osMem.get("free_percent"));

    // Process

    final Map<String, Object> process = (Map<String, Object>) source.get(FIELD_PROCESS);

    monitoringResponse.setJvmProcessOpenFileDescriptors((Integer) process.get("open_file_descriptors"));
    monitoringResponse.setJvmProcessMaxFileDescriptors((Integer) process.get("max_file_descriptors"));

    // JVM

    final Map<String, Object> jvm = (Map<String, Object>) source.get(FIELD_JVM);

    monitoringResponse.setJvmUptimeInMillis(getLongValue(jvm.get("uptime_in_millis")));
    monitoringResponse.setJvmTimestamp(getLongValue(jvm.get("timestamp")));

    final Map<String, Object> jvmMem = (Map<String, Object>) jvm.get("mem");
    monitoringResponse.setJvmHeapCommittedInBytes(getLongValue(jvmMem.get("heap_committed_in_bytes")));
    monitoringResponse.setJvmHeapUsedPercent((Integer) jvmMem.get("heap_used_percent"));
    monitoringResponse.setJvmHeapMaxInBytes(getLongValue(jvmMem.get("heap_max_in_bytes")));
    monitoringResponse.setJvmNonHeapCommittedInBytes(getLongValue(jvmMem.get("non_heap_committed_in_bytes")));
    monitoringResponse.setJvmHeapUsedInBytes(getLongValue(jvmMem.get("heap_used_in_bytes")));
    monitoringResponse.setJvmNonHeapUsedInBytes(getLongValue(jvmMem.get("non_heap_used_in_bytes")));

    final Map<String, Object> jvmMemPools = (Map<String, Object>) jvmMem.get("pools");

    final Map<String, Object> jvmMemPoolsYoung = (Map<String, Object>) jvmMemPools.get("young");

    monitoringResponse.setJvmMemPoolYoungUsedInBytes(getLongValue(jvmMemPoolsYoung.get("used_in_bytes")));
    monitoringResponse
            .setJvmMemPoolYoungPeakUsedInBytes(getLongValue(jvmMemPoolsYoung.get("peak_used_in_bytes")));
    monitoringResponse.setJvmMemPoolYoungMaxInBytes(getLongValue(jvmMemPoolsYoung.get("max_in_bytes")));
    monitoringResponse
            .setJvmMemPoolYoungPeakMaxInBytes(getLongValue(jvmMemPoolsYoung.get("peak_max_in_bytes")));

    final Map<String, Object> jvmMemPoolsOld = (Map<String, Object>) jvmMemPools.get("old");

    monitoringResponse.setJvmMemPoolOldUsedInBytes(getLongValue(jvmMemPoolsOld.get("used_in_bytes")));
    monitoringResponse.setJvmMemPoolOldPeakUsedInBytes(getLongValue(jvmMemPoolsOld.get("peak_used_in_bytes")));
    monitoringResponse.setJvmMemPoolOldMaxInBytes(getLongValue(jvmMemPoolsOld.get("max_in_bytes")));
    monitoringResponse.setJvmMemPoolOldPeakMaxInBytes(getLongValue(jvmMemPoolsOld.get("peak_max_in_bytes")));

    final Map<String, Object> jvmMemPoolsSurvivor = (Map<String, Object>) jvmMemPools.get("survivor");

    monitoringResponse.setJvmMemPoolSurvivorUsedInBytes(getLongValue(jvmMemPoolsSurvivor.get("used_in_bytes")));
    monitoringResponse
            .setJvmMemPoolSurvivorPeakUsedInBytes(getLongValue(jvmMemPoolsSurvivor.get("peak_used_in_bytes")));
    monitoringResponse.setJvmMemPoolSurvivorMaxInBytes(getLongValue(jvmMemPoolsSurvivor.get("max_in_bytes")));
    monitoringResponse
            .setJvmMemPoolSurvivorPeakMaxInBytes(getLongValue(jvmMemPoolsSurvivor.get("peak_max_in_bytes")));

    final Map<String, Object> jvmThreads = (Map<String, Object>) jvm.get("threads");

    monitoringResponse.setJvmThreadCount((Integer) jvmThreads.get("count"));
    monitoringResponse.setJvmThreadPeakCount((Integer) jvmThreads.get("peak_count"));

    final Map<String, Object> jvmGC = (Map<String, Object>) jvm.get("gc");

    final Map<String, Object> jvmGCCollectors = (Map<String, Object>) jvmGC.get("collectors");

    final Map<String, Object> jvmGCCollectorsYoung = (Map<String, Object>) jvmGCCollectors.get("young");

    monitoringResponse
            .setJvmGCCollectorsYoungCollectionCount((Integer) jvmGCCollectorsYoung.get("collection_count"));
    monitoringResponse.setJvmGCCollectorsYoungCollectionTimeInMillis(
            getLongValue(jvmGCCollectorsYoung.get("collection_time_in_millis")));

    final Map<String, Object> jvmGCCollectorsOld = (Map<String, Object>) jvmGCCollectors.get("old");

    monitoringResponse
            .setJvmGCCollectorsOldCollectionCount((Integer) jvmGCCollectorsOld.get("collection_count"));
    monitoringResponse.setJvmGCCollectorsOldCollectionTimeInMillis(
            getLongValue(jvmGCCollectorsOld.get("collection_time_in_millis")));

    return monitoringResponse;
}

From source file:com.mgmtp.perfload.perfalyzer.normalization.MeasuringNormalizingStrategy.java

@Override
public List<ChannelData> normalizeLine(final String line) {
    tokenizer.reset(line);//from  w w  w . j av a2s .  c o m
    String[] tokens = tokenizer.getTokenArray();

    List<ChannelData> channelDataList = newArrayListWithExpectedSize(3);
    ZonedDateTime timestamp;
    try {
        timestamp = ZonedDateTime.parse(tokens[3]);
    } catch (IllegalArgumentException ex) {
        log.error("Invalid data line: {}", line);
        return channelDataList;
    }

    if (!timestampNormalizer.isInRange(timestamp)) {
        log.trace("Skipping measuring entry. Timestamp not in time range of test: " + timestamp);
        return channelDataList;
    }
    StrBuilder sb = new StrBuilder(200);

    long normalizedTimestamp = timestampNormalizer.normalizeTimestamp(timestamp, 0L);

    String responseTimeFirstByte = tokens[MEASURING_RAW_COL_RESPONSE_TIME_FIRST_BYTE];
    String responseTime = tokens[MEASURING_RAW_COL_RESPONSE_TIME];
    String operation = tokens[MEASURING_RAW_COL_OPERATION];
    if (operation == null || operation.isEmpty()) {
        return channelDataList;
    }

    String result = tokens[MEASURING_RAW_COL_RESULT];
    String errorMsg = tokens[MEASURING_RAW_COL_ERROR_MSG];
    String type = tokens[MEASURING_RAW_COL_REQUEST_TYPE];
    String uriString = tokens[MEASURING_RAW_COL_URI];
    String uriAlias = tokens[MEASURING_RAW_COL_URI_ALIAS];

    String uriPath;
    try {
        URI uri = new URI(uriString);
        uriPath = uri.getPath();
        String query = uri.getQuery();
        if (query != null) {
            uriPath += '?' + query;
        }
    } catch (URISyntaxException ex) {
        // this can happen for agent measurings and custom request types
        uriPath = uriString;
    }

    if (uriString.equals(uriAlias)) {
        uriAlias = uriPath;
    }

    String executionId = tokens[MEASURING_RAW_COL_EXECUTION_ID];
    String requestId = tokens[MEASURING_RAW_COL_REQUEST_ID];

    appendEscapedAndQuoted(sb, DELIMITER, normalizedTimestamp);
    appendEscapedAndQuoted(sb, DELIMITER, responseTimeFirstByte);
    appendEscapedAndQuoted(sb, DELIMITER, responseTime);
    appendEscapedAndQuoted(sb, DELIMITER, operation);
    appendEscapedAndQuoted(sb, DELIMITER, type);
    appendEscapedAndQuoted(sb, DELIMITER, uriPath);
    appendEscapedAndQuoted(sb, DELIMITER, uriAlias);
    appendEscapedAndQuoted(sb, DELIMITER, result);
    appendEscapedAndQuoted(sb, DELIMITER, errorMsg);
    appendEscapedAndQuoted(sb, DELIMITER, executionId);
    appendEscapedAndQuoted(sb, DELIMITER, requestId);

    String resultLine = sb.toString();
    channelDataList.add(new ChannelData(CHANNEL_BASE_NAME, operation, resultLine));
    return channelDataList;
}

From source file:ru.jts_dev.gameserver.time.GameTimeService.java

@PostConstruct
private void loadDateTime() {
    final ServerVariableKey key = new ServerVariableKey(gameServerConfig.getServerId(),
            ServerVariableType.SERVER_TIME);
    final ServerVariable serverTime = serverVariablesRepository.findOne(key);

    if (serverTime != null) {
        final String value = serverTime.getValue();
        dateTime = ZonedDateTime.parse(value);
    }//from   w ww  .jav a  2  s  . co  m

    logger.info("Current in-game time is {}.", dateTime);
}