I seem to misunderstand java.util.Date's conversion from and to java.time.Instance. I have some legacy code I need to ineract with, and this code uses java.util.Date in its API.
I am slightly confused when offsets are added in the Date API. It was my understand that Date is a UTC time ("the Date class is intended to reflect coordinated universal time (UTC)"), but when I create a Date from an Instant an offset is added:
public class TestDateInstant {
@Test
public void instantdate() {
Instant i = Instant.now();
System.out.println(i);
Date d = Date.from(i);
System.out.println(d);
assertThat(i, equalTo(d.toInstant()));
}
}
The assertion holds, but the output on the console is:
2017-09-26T08:24:40.858Z
Tue Sep 26 10:24:40 CEST 2017
I am wondering why Date.from uses an offset in this case.