更改日期格式

发布于 2024-07-11 21:17:56 字数 600 浏览 5 评论 0原文

在 Calc 中,我将单元格值设置为“2006/10/03 13:33:55.448”,Calc 表示它是标准格式。 我正在使用 Java 执行此操作,我想将格式设置为“DD.MM.YY HH:MM:SS AM/PM”:

XNumberFormatTypes xFormatTypes = (XNumberFormatTypes) UnoRuntime.queryInterface(XNumberFormatTypes.class, xNumberFormats);
int myDateFormat = xNumberFormats.addNew("DD.MM.YY HH:MM:SS AM/PM", defaultLocale);
XPropertySet cellRangePropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, cellRange);
cellRangePropSet.setPropertyValue("NumberFormat", new Integer(myDateFormat));

但单元格看起来仍然相同。 我是否必须刷新范围才能使单元格显示“03.10.06 01:33:55 PM”?

In Calc I set a cell value to "2006/10/03 13:33:55.448" and Calc says it is Standard format. I'm doing this with Java and I want to set the format to "DD.MM.YY HH:MM:SS AM/PM":

XNumberFormatTypes xFormatTypes = (XNumberFormatTypes) UnoRuntime.queryInterface(XNumberFormatTypes.class, xNumberFormats);
int myDateFormat = xNumberFormats.addNew("DD.MM.YY HH:MM:SS AM/PM", defaultLocale);
XPropertySet cellRangePropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, cellRange);
cellRangePropSet.setPropertyValue("NumberFormat", new Integer(myDateFormat));

but the cell stil looks the same. Do I have to refresh the range so that the cell would display "03.10.06 01:33:55 PM"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2024-07-18 21:17:56

不,我不会在我的任何项目中这样做。
问题是我在 Calc 中导入了一个 csv 文件并指定日期列的类型为标准。 然后我将其更改为日期(YY/MM/DD),代码神奇地工作了。 :)

Nope, I'm not doing that in any of my projects.
The problem was that I imported a csv file in Calc and specified that the date column was of type Standard. Then I changed it to Date (YY/MM/DD) and the code magically worked. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文