+ 2
Why it gives wrong Output when I run it on June 13,2021 2:01 AM
3 Respuestas
+ 2
By default, the time is returned according to GMT.
Use java.time.ZonedDateTime.now() method along with java.time.ZoneId to get the time according to your timezone.
https://code.sololearn.com/cnn4tC7l6pR7/?ref=app
java.time.ZoneId:
https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html
java.time.ZonedDateTime:
https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html
I got the ZonedDateTime idea from StackOverflow, so there could be better ways that I don't know about.
+ 2
Thanks XXX and Simon Sauter
+ 1
I'm not sure what you mean. But did you take into account timezones? The output is in GMT.