Skip to content
Advertisement

Java Calendar not giving end of hour

Based on Epoch seconds, I convert it to the start of hour and end of hour.

JavaScript

The start of hour seems correct, but the end of hour is not giving it right, instead of upto 59 minute, 59 second, 999 millisecond it is giving only half hour difference.

Advertisement

Answer

You are mixing java.time and java.util.Calendar types. Don’t do that. For one thing, you’re losing the TimeZone you specified when you clone. Basically, Calendar is a mess. But you don’t need it here, something like

JavaScript

Should meet your needs. Here that outputs

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement