0

I have seen the link apache poi DataFormatter on cell containing date solution updated for "dd/MM/yyyy" format using SimpleDateFormat DtFormat = new SimpleDateFormat("dd/MM/yyyy"); In my case i'm not aware of the format..it may be in any date format. In this case how can I handle?

I have tried to read the date value from the date cell in the xlsx file.

cell having data as: 8/5/2016

output im getting is : 8/5/16

I need the same format as mentioned in that date cell.

if know the format I can use SimpleDateFormat DtFormat = new SimpleDateFormat("dd/MM/yyyy"). without knowing the format is there any way to get it?

Sample code:

int r1c1=5;
switch (cell.getCellType()) 
{
case XSSFCell.CELL_TYPE_NUMERIC:   
    if (HSSFDateUtil.isCellDateFormatted(cell)){
        DataFormatter formatter = new DataFormatter();
        //Value variable displaying output as 8/5/16 instead of 8/5/2016
        value = formatter.formatCellValue(cell);
        Hm.put(r1c1, value); //using hashmap to store value
    }
    break;
}
Community
  • 1
  • 1
Dinesh
  • 61
  • 1
  • 1
  • 11
  • @PaoloForgia I have used the same thing as mentioned in that link. I need year in that date to be displayed completely(8/5/2016) – Dinesh Aug 08 '16 at 10:02
  • 2
    @Dinesh: See http://stackoverflow.com/questions/34900605/excell-cell-style-issue/34902174#34902174 – Axel Richter Aug 08 '16 at 10:35
  • 1
    @all who upvoted possible duplicate: Have you even read the linked answer? There the `12/21/14` is exactly **not** as it is in Excel. In Excel it is `12/21/2014`. So how shall this answer helping here? – Axel Richter Aug 08 '16 at 12:47
  • @AxelRichter: its working. Thanks a lot. I have been searching this for long time :) – Dinesh Aug 08 '16 at 13:10

0 Answers0