I'm using Java Excel API to read data from Excels sheets in my Android project. I have some columns formated as time like this:
At first I tried read this cell using that code:
String cellContent = cell.getContents();
But as result I got content without hours eg :59:59. After that I tried get this time as seconds. I noticed that when cell data is get as DateCell, Date contents object has negative timestamp. I did some trick and I found value of timestamp for 0:00:00. I set variable with this value as positive (2209161600000L). Now I just add this variable to negative timestamp from cell and devide result by 1000 (milliseconds in second). Everything is fine until 23:59:59. Values above have extra 24 h (24:00:00 is reading as 48:00:00). I saw that Excel keeps this values in different ways.
I can just subtract this 24h but it isnt elegant solution. I want to get content as #:##:## string (which I prefer) or as seconds. Is there any good solution for this issue?
Java Excel API is not developed since 2010 so I change library to Apache POI. Time cell is returned as fraction of 24h.
double fractionOfDay = cell.getNumericCellValue();
long timeInSeconds = Math.round(numericValue * SECONDS_IN_DAY);
Now everything works fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.