gpt4 book ai didi

java - 在Java中显示Excel工作表xlsx中的日期

转载 作者:行者123 更新时间:2023-12-01 17:06:45 26 4
gpt4 key购买 nike

我在 Excel 工作表 (xlsx) 的一个单元格中将日期保存为 2013 年 6 月 24 日。检索时,它向我显示的是 174-Jun-2013

代码是

    String ret="";

if(c.getCellType()==Cell.CELL_TYPE_NUMERIC)
{
if(col==0)
{
ret=new java.text.DecimalFormat("0").format(c.getNumericCellValue());
}
else if(col==8)
{
if(HSSFDateUtil.isCellDateFormatted(c))
{
DateFormat df=new SimpleDateFormat("DD-MMM-YYYY");
ret=df.format(c.getDateCellValue());
}
}
else
{
ret=""+c.getNumericCellValue();
}
}
else if(c.getCellType()==Cell.CELL_TYPE_STRING)
{
ret=""+c.getStringCellValue();
}

return ret;

请帮帮我。

提前致谢。

最佳答案

用途:

DateFormat df=new SimpleDateFormat("dd-MMM-yyyy");

而不是

DateFormat df=new SimpleDateFormat("DD-MMM-YYYY");

因为:

D = 一年中的某一天d = 一个月中的某天

关于java - 在Java中显示Excel工作表xlsx中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25216462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com