我想把这个基于joda库的Java移植到java.time
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.Instant;
private DateTime createdDate;
private Duration executionTime;
private Instant requestTime;
public void startTimerProcess() {
this.requestTime = Instant.now();
}
public void endTimerProcess() {
this.executionTime = new Duration(requestTime, Instant.now());
}
我试过这个:
import java.time.Duration;
import java.time.Instant;
import java.time.OffsetDateTime;
private OffsetDateTime createdDate;
private Duration executionTime;
private Instant requestTime;
public void startTimerProcess() {
this.requestTime = Instant.now();
}
public void endTimerProcess() {
this.executionTime = Duration.of(requestTime.toEpochMilli(), Instant.now());
}
对于第Duration.of
行,我收到错误:
Required type: TemporalUnit
Provided: Instant
你能告诉我实施他迁移的正确方式是什么吗?