Converting Number representation of Date in excel to Date in java

前端 未结 4 503
暖寄归人
暖寄归人 2020-11-30 10:05

I have date column in excel, but when I\'m reading in my java application I\'m getting value as number

Example

Excel Date

1/1/2013

4条回答
  •  甜味超标
    2020-11-30 10:45

    Excel’s serialized dates are the number of days since 1/1/1900. In order to figure out the date again, we have to add the serial number worth of days.

    for Java 8 without any dependency

    ```

      /*
    
        1900-1-0            0
        1900-1-1            1
        1900-1-2            2
        1900-1-3            3
    
    
         */
    
    
        int days = 43323;
        LocalDate start = LocalDate.of(1900, 1, 1);
        LocalDate today = LocalDate.of(2018, 8, 11);
    
    
        // days to date
        LocalDate date = start.plusDays(days).minusDays(2);
    
        System.out.println(date);
    
        // date to days
        long days1 = ChronoUnit.DAYS.between(start, today) + 2;
        System.out.println(days1);
    

    ```

提交回复
热议问题