Here you can find the source of toDoubleExcelFormat(LocalDateTime date, boolean date1904)
public static String toDoubleExcelFormat(LocalDateTime date, boolean date1904)
//package com.java2s; //License from project: Open Source License import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; public class Main { public static String toDoubleExcelFormat(LocalDateTime date, boolean date1904) { if (date == null) return ""; LocalDateTime from;/*from www .j a v a 2 s.c o m*/ // Excel has 2 date systems: // - https://support.microsoft.com/pt-br/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel if (date1904) { from = LocalDateTime.of(1904, 1, 1, 0, 0, 0); } else { from = LocalDateTime.of(1900, 1, 1, 0, 0, 0); // http://polymathprogrammer.com/2009/10/26/the-leap-year-1900-bug-in-excel/ if (date.isBefore(LocalDateTime.of(1900, 3, 1, 0, 0, 0))) { from = from.minusDays(1); } else { from = from.minusDays(2); } } long millis = from.until(date, ChronoUnit.MILLIS); // excel hours are represented as a fraction of a day double dayMillis = 24.0 * 60.0 * 60.0 * 1000.0; return Double.toString(millis / dayMillis); } }