直到現在我正在使用
val date = Instant.now(Clock.system(ZoneId.of("UTC")))
生成即時時間戳。現在我需要用我想要指定的日期替換它,例如“2021-05-03T00:00:00.000Z”。當我將它作為字串插入到函式中時,這個想法給了我錯誤“型別不匹配。必需:即時!找到:字串”。我無法更改該功能,因為我無法訪問它。所以我需要以某種方式把這個日期變成“即時!” 班級。
這就是我無法更改的功能的樣子
public TimeTZ(Instant timestamp, Boolean isLocal) {
this.timestamp = timestamp;
this.isLocal = isLocal;
}
uj5u.com熱心網友回復:
val date = Instant.parse("2021-05-03T00:00:00.000Z")
將字串轉換為一個Instant(或其他型別的值)稱為決議。所以使用 的parse方法Instant。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/362349.html
標籤:日期 科特林 时间 java.time.instant
