POI Java Date to Excel seconds difference

ぃ、小莉子 提交于 2019-12-13 02:12:14

问题


guys.

I'm having some trouble when exporting dates from Java to Excel cells using Apache POI library.

It's a marvelous tool and very easy to understand and use, but right now it is giving me some headaches!

Here's the thing: I'm writing an application that validates certifications using a code made out of 2 letters followed by 9 digits. The last 4 digits are made by the sum of each number representing day, month and year as well as hour, minute and seconds in the instant the code generation took place. e.g. 03/31/2015 17:30:32 (24 hour format) => 3 + 31 + 2015 + 17 + 30 + 32 = 2128. Everything works fine, code gets generated, workbook gets a new line with each data, including date of generation. But when I open workbook to see the result, generation date cell gets slightly different from actual date value and doing math again results in those 4 last digits giving a different sum, something like 2126 or 2130 (varies each time code runs).

I google'd and found its gotta be related to how MS Excel and Java handles Date calculation. Excel use days since 01/01/1900 and Java miliseconds since 01/01/1970.

Does someone know any kind of workaround to it?

Thanks.

来源:https://stackoverflow.com/questions/29378976/poi-java-date-to-excel-seconds-difference

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!