Why it gives wrong Output when I run it on June 13,2021 2:01 AM | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why it gives wrong Output when I run it on June 13,2021 2:01 AM

https://code.sololearn.com/cZo0ZiysdLX9/?ref=app

12th Jun 2021, 8:32 PM
Atul [Inactive]
3 Answers
+ 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.
13th Jun 2021, 3:38 AM
XXX
XXX - avatar
+ 2
Thanks XXX and Simon Sauter
13th Jun 2021, 4:09 AM
Atul [Inactive]
+ 1
I'm not sure what you mean. But did you take into account timezones? The output is in GMT.
12th Jun 2021, 10:11 PM
Simon Sauter
Simon Sauter - avatar