getDay(),getMonth(),getYear()

发布于 2024-12-28 14:12:41 字数 268 浏览 2 评论 0原文

我有一个名为 $F{Fecha} 的时间戳文本字段,我想从中获取日、月和年。我创建了 3 个变量 var1、var2、var3,并在它们的表达式中添加了以下 $F{Fecha}.getDay()、$F{Fecha}.getMonth()、$F{Fecha}.getYear() ;它给了我一个返回值,但它们是错误的值,即如果我的日期是20120118,它会返回day=3,month=0,yearh=112。

我该如何解决这个问题? 提前致谢。

PD。我使用的是iReport 4.0.0

I have a timestamp textField called $F{Fecha}, and I want to get from it the day,month, and year. I've create 3 variables var1,var2,var3 and in their expressions I've put the following $F{Fecha}.getDay(), $F{Fecha}.getMonth(),$F{Fecha}.getYear(); it gives me in return a value but they're wrong values,ie if my date is 20120118 it returns me day=3, month=0,yearh=112.

How can I do to fix this?
Thanks in advance.

PD. I'm using iReport 4.0.0

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

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

发布评论

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

评论(3

瑾兮 2025-01-04 14:12:41

下面是使用 Java 表达式实现这一点的方法:

Day:
new Integer($F{Fecha}.getDate())

月份:
new Integer($F{Fecha}.getMonth()+1)

年:
新整数($F{Fecha}.getYear()+1900)

Here is a way to do it with Java expressions:

Day:
new Integer($F{Fecha}.getDate())

Month:
new Integer($F{Fecha}.getMonth()+1)

Year:
new Integer($F{Fecha}.getYear()+1900)

甜妞爱困 2025-01-04 14:12:41

我同意亚历克斯的观点:通过字符串解析来提取日期信息是一个坏主意。例如:使用不同的区域设置运行报表,您会发现报表以意想不到的方式中断。

Java 没有为此目的内置非常好的日期处理。但是您可以使用 Joda-Time 或 Apache Commons Lang 来获取许多有用的功能。

I'm with Alex: string parsing to pull out date information is a bad idea. For example: run the report using a different Locale, and you'll find the your report breaks in unexpected ways.

Java doesn't have very good date handling built in for this purpose. But you can use Joda-Time or Apache Commons Lang to get a bunch of helpful functions.

不寐倦长更 2025-01-04 14:12:41

如果可能的话,您可以在 SQL 中执行此操作。

MySQL 有 MONTH()、DAY() 和 YEAR() 函数可以执行此操作。

If possible, you could do this in the SQL.

MySQL has MONTH(), DAY() and YEAR() functions that would do this.

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