poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Max Birkoff <maxbirk...@yahoo.com>
Subject getJavaDate(double date, java.util.TimeZone tz)
Date Mon, 13 Aug 2012 23:08:59 GMT
Hi there,

I see in POI javadoc:
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);
                 destinationCell = new MyDateCell(calendar);

Please let me know what you think. Thanks much in advance,


To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org

View raw message