Cannot convert the date format through POI
am currently using POI to manipulate data into excel file,
.......
styleDates.setDataFormat(HSSFDataFormat.getBuiltinFormat("dd/mm/yyyy hh:mm"));
cellG.setCellStyle(styleDates)
cellG.setCellValue(processStartDate);
processStartDate is Timestamp type, which value is getting from database, but when data write into excel file, its format is a numberic number rather than a pre-define format "dd/mm/yyyy hh:mm", why?
[452 byte] By [
henry_22a] at [2007-11-27 4:29:38]

# 1
When u get the date it will be in double format.
Convert that format into java format.
use this code:
public static final int[] days_b4_month = {
// Don't forget to check for > leap year!
0,
31,
31+28,
31+28+31,
31+28+31+30,
31+28+31+30+31,
31+28+31+30+31+30,
31+28+31+30+31+30+31,
31+28+31+30+31+30+31+31,
31+28+31+30+31+30+31+31+30,
31+28+31+30+31+30+31+31+30+31,
31+28+31+30+31+30+31+31+30+31+30,
31+28+31+30+31+30+31+31+30+31+30+31};
public static String getMonth( int iMonth ){
String strMonth="";
switch (iMonth) {
case 1:
strMonth="Jan";
break;
case 2:
strMonth="Feb";
break;
case 3:
strMonth="Mar";
break;
case 4:
strMonth="Apr";
break;
case 5:
strMonth="May";
break;
case 6:
strMonth="Jun";
break;
case 7:
strMonth="Jul";
break;
case 8:
strMonth="Aug";
break;
case 9:
strMonth="Sep";
break;
case 10:
strMonth="Oct";
break;
case 11:
strMonth="Nov";
break;
case 12:
strMonth="Dec";
break;
default:
break;
}
return strMonth;
}
public static String convertExcelDateToUtilDate(double excelDate)
{
System.out.println("-inside Convert Execel Date-"+excelDate);
double excelDateDouble=excelDate-1;
System.out.println("-inside Convert Execel Date--s--"+excelDateDouble);
boolean leap_day = false;
int month = 0;
int day = 0;
int yr = (int) (excelDateDouble / 365.25);
int year = yr + 1900;
int yrDay = (int) (excelDateDouble) - (yr * 365 + (int) (yr / 4));
if ((yr % 4) == 0)// Leap years. (N.B. this algorithm will be inaccurate after 2099!)
{
if (yrDay == 59) // It's Feb 29! - Special case
leap_day = true;
else if (yrDay < days_b4_month[2])
yrDay++; // Compensate for leap day.
}
if (leap_day)
{
month = 2;
day = 29;
}
else
{
month = 0;// start in January.
while (days_b4_month[month] < yrDay)
month++;
day = yrDay - days_b4_month[month-1];
}
String ret = new String(day + "-" + getMonth(month) + "-" + year);
System.out.println("--Date is :"+ret);
return ret;
}
you will get java date then just proceed