Java examples for java.time:LocalDateTime
calculate Seconds Between LocalDateTime
//package com.java2s; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; public class Main { public static long calculateSecondsBetweenLocalDateTime( LocalDateTime fromDateTime, LocalDateTime toDateTime) { LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime); long years = tempDateTime.until(toDateTime, ChronoUnit.YEARS); tempDateTime = tempDateTime.plusYears(years); long months = tempDateTime.until(toDateTime, ChronoUnit.MONTHS); tempDateTime = tempDateTime.plusMonths(months); long days = tempDateTime.until(toDateTime, ChronoUnit.DAYS); tempDateTime = tempDateTime.plusDays(days); long hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS); tempDateTime = tempDateTime.plusHours(hours); long minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES); tempDateTime = tempDateTime.plusMinutes(minutes); long seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS); //do some addition return 0 + Math.round(((double) years) * 31556900d) + Math.round(((double) months) * 2629740d) + Math.round(((double) days) * 86400d) + Math.round(((double) hours) * 3600d) + Math.round(((double) minutes) * 60d) + Math.round(((double) seconds)); }/*from w ww .ja v a2 s . c o m*/ }