public DateTest(String filename) throws IOException { DataFormat format = null; CellStyle cellStyle = null; Workbook workbook = null; Sheet sheet = null; Row row = null; Cell cell = null; FileOutputStream f = null; BufferedOutputStream b = null; StringBuilder refersToFormula = null; if(filename.endsWith(".xlsx")) { workbook = new XSSFWorkbook(); } else { workbook = new HSSFWorkbook(); } try { sheet = workbook.createSheet("Test"); row = sheet.createRow(0); cell = row.createCell(0); cellStyle = workbook.createCellStyle(); format = workbook.createDataFormat(); cellStyle.setDataFormat(format.getFormat("[$-809]dd mmmm yyyy;@")); cell.setCellStyle(cellStyle); cell.setCellValue(new Date()); f = new FileOutputStream(filename); b = new BufferedOutputStream(f); workbook.write(b); } finally { if(b != null) { b.close(); } } }