I'm making an application for Android in Android Studio with Java. I'm working with dates and times. I'm trying to produce a Unix timestamp from a custom given point in time. As an example, the following piece of code
LocalDateTime aDateTime = LocalDateTime.of(2021, 4, 30, 8, 30);
ZoneId zoneId = ZoneId.systemDefault();
int x = Math.toIntExact(aDateTime.atZone(zoneId).toEpochSecond());
produces a Unix timestamp 1619760600. However, when I enter this into any online converter, it produces a time of 04/30/2021 @ 5:30am (UTC). This is off by 3 hours from the original inserted time which is the exact amount in hours that my timezone differs from UTC00:00.
The problem seems to be my inability to understand timezones in Java. So my question is, how do I factor in the timezone correctly so that a correct UnixTimeStamp is produced?