0

Error with java.time??

I wrote a program that uses java.time It works just fine save for the method to get the current hour. e.g. it returned 21 when it should be 13 or 2 when it should be 18 https://code.sololearn.com/cS2lKCYqU29W/?ref=app

3rd Jan 2020, 2:55 AM
Oceanlight
Oceanlight - avatar
4 Respuestas
+ 4
Not sure but I guess it probably returns the server time on which it's running.
3rd Jan 2020, 4:05 AM
Avinesh
Avinesh - avatar
+ 2
I have changed your code a little using zoneid and it is working for me https://code.sololearn.com/ca59WzX8nE7q/?ref=app I hope this helps you
3rd Jan 2020, 7:44 AM
Julio Codesal
Julio Codesal - avatar
+ 2
for name of month there is API import java.time.format.TextStyle; import java.util.Locale; /.. String monthName = Month.of(month).getDisplayName(TextStyle.FULL, Locale.getDefault() );
3rd Jan 2020, 7:38 PM
zemiak
+ 1
Only if you run it on your system, it will return the system date and time when you call the now(). On sololearn it's not the same. Even if you use the ZoneId class then the output will give the correct date but your time will be the difference between time in your zone and the GMT. If you are ahead then it will result in + or if you are lagging then it will result in - time.
3rd Jan 2020, 8:05 AM
Avinesh
Avinesh - avatar