小编wyk*_*dz1的帖子

如何用 java.time.clock 模拟日期时间?

为什么用下面的代码生成的日期将给定时间偏移到 11:00:00.00?

test("shouldReturnGivenMockedDateTime") {
  val mockedDateTime = "2020-01-01T10:00:00.00Z"
  val clock: Clock = Clock.fixed(Instant.parse(mockedDateTime), TimeZone.getDefault.toZoneId);
  val result = LocalDateTime.ofInstant(clock.instant, TimeZone.getDefault.toZoneId)
  assert(result.toString == "2020-01-01T10:00") // FALSE!!!
  assert(result.toString == "2020-01-01T11:00") // TRUE
}
Run Code Online (Sandbox Code Playgroud)

java datetime scala java-time

0
推荐指数
1
解决办法
574
查看次数

标签 统计

datetime ×1

java ×1

java-time ×1

scala ×1