How can I find the amount of seconds passed from the midnight with Java?
If you’re using Java >= 8, this is easily done : ZonedDateTime nowZoned = ZonedDateTime.now(); Instant midnight = nowZoned.toLocalDate().atStartOfDay(nowZoned.getZone()).toInstant(); Duration duration = Duration.between(midnight, Instant.now()); long seconds = duration.getSeconds(); If you’re using Java 7 or less, you have to get the date from midnight via Calendar, and then substract. Calendar c = Calendar.getInstance(); long now = … Read more