I have an excel sheet inside in particular cell contain date value now this date value can be in any format may be UK format or US format there are different date formats as i can check when i rite click on format cell options in excel sheet i can see it as date type shown in excel now please advise how java code determine the same date format that is i am using poi in java now please advise how poi can determine that cell type is of date and the same format also that cell type has which type of date format please advise .
Asked
Active
Viewed 3,293 times
1 Answers
1
There are 2 cases, the cell may have been date formatted by excel, you can check it with these methods. Below is an example:
if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC && HSSFDateUtil.isCellDateFormatted(cell)){
date = cell.getDateCellValue();
}
If it's not date formatted then, we can parse the date from string using DateUtils library, by passing the array of possible date formats.

Darshan Mehta
- 30,102
- 11
- 68
- 102
-
Thanks a lot i agree that few cells data type in excel sheet is of date type that it is formatted one but few dates have been of general data type in excel so excel treats these cells as string cell type , now the for this the approach that you have suggested is to use dateutils library can you lease show how it is being used as i want to store the dates coming with general data type in UK format dd/mm/yyyy , Thanks in advance – hfkjflhf jgdjdhkd Dec 04 '15 at 16:35
-
You need to use parseDateStrictly method, refer to this so answer: http://stackoverflow.com/questions/19269888/parse-string-to-date-using-different-formats-patterns – Darshan Mehta Dec 04 '15 at 16:38