diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java b/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java index 80807fb64..e9c14b093 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TDate.java @@ -92,7 +92,7 @@ public class TDate implements TComparable { if (PlatformDetector.isLowLevel()) { return initUtcDateLowLevel(year, month, date, hrs, min, sec); } else { - return (long) JSDate.UTC(year, month, date, hrs, min, sec); + return (long) JSDate.UTC(year + 1900, month, date, hrs, min, sec); } } diff --git a/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java b/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java index 90a18879b..e3e16436d 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/DateTest.java @@ -34,4 +34,14 @@ public class DateTest { assertEquals(4, date.getDate()); assertEquals(115, date.getYear()); } + + @SuppressWarnings("deprecation") + @Test + public void setsUTC() { + long epochTime = Date.UTC(2023, 1, 20, 10, 0, 0); + Date date = new Date(epochTime); + assertEquals(2023, date.getYear()); + assertEquals(1, date.getMonth()); + assertEquals(20, date.getDate()); + } }