I have get the date from excel sheet using POI using the below code,
if (DateUtil.isCellDateFormatted(currentCell))
{
Date date = currentCell.getDateCellValue();
cellValue = date.getDate() + "/" + (date.getMonth() + 1) + "/" + (1900 + date.getYear());
}
By default the date format of excel sheet is MM/dd/yy. But if I make the month value is greater than 12 (i.e >= 13), the format is changed to dd/MM/yy.
By the above code,If I give date as 10/11/2010, it gives month as 10 and date as 11. If I give it like 15/10/2010, I got month as 10 and date as 15.
But I need to maintain the one format that is dd/MM/yyyy. How can I achieve this?
Use SimpleDateFormat to format the date because “currentCell.getDateCellValue()) returns a Date.
This should prevent the automatic conversion that is taking place.