title: Get format of Date for date column in Excel
body: <p>I am using Apache POI 3.11 version for reading and writing an excel file in Java</p>
  
  <p>In my input excel file, I have a column which contains date. Date can be in any format like say dd/mm/yyyy hh:mm or yy/mm/dd  etc. While reading the file, I can get date in any format.</p>
  
  <p><a href="https://i.stack.imgur.com/zafPM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zafPM.png" alt="enter image description here"></a></p>
  
  <p>When I am creating the new excel file as output, I want to write date column. But I want to use the same format of date that was present in the input excel file.</p>
  
  <p>Is there any way, by which I can get out the date format present in the input excel file (Above screen shot you can see the date was in mm/dd/yyyy hh:mm:ss PM format)</p>
  
  <p>I do not want to use <code>***getCellStyle***</code> function, because it returns me the complete style of cell including the font color, background color etc.
  I just want the date format information of a cell that was present in the input excel file.</p>
  
  <p>Way I am trying :</p>
  
  <pre><code>CellStyle outputStyle = wb.createCellStyle();
  Font textFont = wb.createFont();
   textFont.setFontName("Arial");
  textFont.setFontHeightInPoints((short) 10);
  textFont.setColor(IndexedColors.BLACK.getIndex());
  .setFont(textFont);
  
   if (DateUtil.isCellDateFormatted(icell)) {
   outputStyle.setDataFormat(icell.getCellStyle().getDataFormat());
   ocell.setCellValue(icell.getDateCellValue());
   }
  
   ocell.setCellStyle(outputStyle);
  </code></pre>
  
  <p>It is writing the value of Date in the cell as number.</p>