Or (-> (java.time.ZonedDateTime/now) .getHour) though there may be different time semantics between the two platforms that you may or may not want to reconcile.
Just realize that the hours you will get back depends on the time zone.
For example, it can be 7pm in one part of the world and 10pm in another.
Be careful when using time, if you don’t specify a timezone in your case, for both JS and Java, what timezone will their respective runtime default too? It’s a mystery…
Especially the logic to get a default time zone might differ between one browser to another and from what the Java VM will do.
Just an FYI.
P.S.: I would also personally lean on the java.time APIs, it’s the newer time API in Java, the Calendar/Date stuff in java.util is very old, and while it also works fine, they’ve become a bit out of fashion.