Hi there,
I see in POI javadoc:
http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DateUtil.html
that this method:
getJavaDate(double date, java.util.TimeZone tz)
is implemented. However when I javap the jar:
$ javap -classpath . org.apache.poi.ss.usermodel.DateUtil | grep getJavaDate
public static java.util.Date getJavaDate(double);
public static java.util.Date getJavaDate(double, boolean);
I don't see that method.
I've implemented the following block of code. If you're interested I can help
factor it into your desired shape:
case Cell.CELL_TYPE_NUMERIC:
Double d = excelCell.getNumericCellValue();
if(DateUtil.isCellDateFormatted(excelCell)) {
// TimeZone timezone =
TimeZone.getTimeZone("America/Los_Angeles");
// Locale locale = Locale.US;
// This is so complicated because excel doesn't have a concept
of or support for timezone.
// POI assumes that the timezone for the date is the default
JVM timezone
// Get help from POI getting the date object:
Date date = DateUtil.getJavaDate(d);
long originalDateEpoch = date.getTime();
// Find out what time zone we're running in
TimeZone thisMachineTZ = TimeZone.getDefault();
int thisMachineOffset =
thisMachineTZ.getOffset(date.getTime());
// And find out what time zone the caller wanted to interpret
this date in:
int desiredOffset = timezone.getOffset(date.getTime());
// Finally, patch up the date so that it's in the correct
timezone
date.setTime(originalDateEpoch + thisMachineOffset -
desiredOffset);
Calendar calendar = Calendar.getInstance(timezone, locale);
calendar.setTime(date);
destinationCell = new MyDateCell(calendar);
Please let me know what you think. Thanks much in advance,
max
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]