LocalTime | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

LocalTime

https://code.sololearn.com/c6MfL0XX35ZZ/?ref=app When I write this code, it gives me time 5 hours later than my actual local time, which is EST (Eastern Standard Time). For example, they give me 15:58:00 when EST is 10:58:00. I was wondering why this happens and where the actual time is coming from. ''' import java.time.LocalDate; import java.time.LocalTime; import java.time.ZoneId; public class Program { public static void main(String[] args) { LocalDate myObj = LocalDate.now(); System.out.println(myObj); LocalTime myTime = LocalTime.now(); System.out.println(myTime); } } '''

31st Dec 2019, 4:04 PM
Han Lee
Han Lee - avatar
1 Answer
+ 2
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html Edit: I'm not sure but I think it returns the standard GMT but you can use the TimeZone class and the ZoneID to get the correct result based on your zone.
31st Dec 2019, 4:31 PM
Avinesh
Avinesh - avatar