Sorry, didn't read your question carefully:
The Date object is parsed from a string input in a Struts Action:
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String input = (String) dynaForm.get("payDate");
Date payDate = df.parse(input);
When I do a payDate.toString, I get:
Sat Nov 01 00:00:00 CST 2003
When I view a cell that's been set to that date in Excel, I see:
11/2/07
This happens if I format the cell programatically, or if I use excel to set
the cell formatting.
Thanks,
-Sasha
On 11/25/03 3:05 PM, "Sasha Borodin" <[EMAIL PROTECTED]> wrote:
> Andrew,
>
> HSSFCellStyle dateStyle = wb.createCellStyle();
> dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
>
> HSSFRow header = sheet.getRow((short) 1);
> header.createCell((short) 1).setCellValue(payDate);
> header.getCell((short) 1).setCellStyle(dateStyle);
>
> This is my exact code. I use the HSSF usermodel classes directly (no cocoon
> or anything). The excel file looks the same on mac and pc, btw.
>
> Thanks,
>
> -Sasha
>
> On 11/25/03 1:48 PM, "Andrew C. Oliver" <[EMAIL PROTECTED]> wrote:
>
>> Show me how you're creating that date.
>>
>> On 11/25/03 11:08 AM, "Sasha Borodin" <[EMAIL PROTECTED]> wrote:
>>
>>> Howdy,
>>>
>>> First let me say what a cool product POI is...I've only been using it a
>>> couple of hours, with some some amazing(ly easy) results!
>>>
>>> I've run into a slight snag, and searching the archives has not yielded an
>>> answer yet. The problem I'm having is that the dates displayed in Excel are:
>>> - 1 calendar day ahead
>>> - and 4 years ahead
>>>
>>> Ahead of what i'm expecting, that is ;-) I use this code snippet to insert
>>> Date values into cells:
>>>
>>> HSSFRow header = sheet.getRow((short) 0);
>>> header.createCell((short) 0).setCellValue(aDate);
>>>
>>> Of course I also create a date style, and set the cell style to that.
>>>
>>> So for example, this is some debugging (toString) for 3 dates:
>>>
>>> Sat Nov 01 00:00:00 CST 2003
>>> Sat Nov 15 00:00:00 CST 2003
>>> Sun Nov 16 00:00:00 CST 2003
>>>
>>> And here is what shows up in Excel (in both the cell and formula bar):
>>>
>>> 11/2/07
>>> 11/16/07
>>> 11/17/07
>>>
>>> I have a feeling it has something to do with interpreting the zero's for
>>> time (which day does midnight belong to...), but I have no clue what the
>>> problem could be for the year offset.
>>>
>>> Any input would be greatly appreciated. Thank you!
>>>
>>> -Sasha Borodin
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]