我想把这个基于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
你能指导我什么是实施他的迁移的正确方法吗?
Duration#between(Instant, Instant)
:
public void endTimerProcess() {
this.executionTime = Duration.between(requestTime, Instant.now());
}