我有一个要输入 Instant 的 ArrayList,但无论我尝试在数组上做什么,它都不允许我将其转换为 Instant 格式。错误在于它试图将字符串添加到 Instant 的 ArrayList。
@Data
@RequiredArgsConstructor
@AllArgsConstructor
public static class LiveData {
private final String location;
private final String metric;
private Double data = null;
private Instant timestamp = null;
}
private void onConnectionOpened() {
try {
int i = 0;
final List<Sensor> sensors = clientConnection.querySensors().get();
final List<String> metric = sensors.stream().map(sensor -> sensor.getLocation()).collect(Collectors.toList());
final List<String> location = sensors.stream().map(sensor -> sensor.getMetric()).collect(Collectors.toList());
List<Instant> timestamps = new ArrayList<>();
List<Instant> times = new ArrayList<>();
List<Double> datavalues = new ArrayList<>();
while (i < sensors.size()) {
final DataPoint data = clientConnection.queryValue(new Sensor(location.get(i), metric.get(i))).get();
timestamps.add((Util.TIME_FORMAT.format((new Date(data.getTime()).toInstant()))));
datavalues.add(data.getValue());
i++;
}
i = 0;
List<LiveData> testcol = new ArrayList<>();
while (i < sensors.size()) {
//LiveData temporary = new LiveData(location.get(i), metric.get(i));
LiveData temporary = new LiveData(location.get(i), metric.get(i), datavalues.get(i), timestamps.get(i));
testcol.add(temporary);
i++;
}
ObservableList<LiveData> livedata = FXCollections.observableArrayList(testcol);
Platform.runLater(() ->
tvData.setItems(livedata));
//Thread.sleep(10000);
//onConnectionOpened();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
我希望能够拥有 Instants 的 ArrayList,而不是像这样使用它:
LiveData temporary = new LiveData(location.get(i), metric.get(i), datavalues.get(i), timestamps.get(i));
供以后在 TableView 中使用。
我正在格式化Instant
对象。我使用该格式是为了更好地输出实际时间戳,因为现在它看起来像这样:2019-07-18T05:35:00Z。我希望它是 2019-07-18 07:35:00。