简体   繁体   English

Jasper报表中的SimpleDateFormat + java.sql.Timestamp

[英]SimpleDateFormat + java.sql.Timestamp in Jasper Reports

I have a timezone-delicate report in Jasper and I can't really seem to figure out how to show a few dates relative to a timezone. 我在Jasper中有一个精美的时区报告,但我似乎还真不知道如何显示相对于时区的一些日期。

I have a view which returns dates with the following format: 我有一个视图,它以以下格式返回日期:

"2015-03-02 11:45:00+01" “ 2015-03-02 11:45:00 + 01”

"2015-03-02 23:59:59+01" “ 2015-03-02 23:59:59 + 01”

"2015-03-03 00:00:00+01" “ 2015-03-03 00:00:00 + 01”

"2015-03-03 08:00:00+01" “ 2015-03-03 08:00:00 + 01”

"2015-03-03 09:20:00+01" “ 2015-03-03 09:20:00 + 01”

"2015-03-03 11:00:00+01" “ 2015-03-03 11:00:00 + 01”

"2015-03-03 09:00:00+01" “ 2015-03-03 09:00:00 + 01”

"2015-03-03 09:30:00+01" “ 2015-03-03 09:30:00 + 01”

etc (notice the +01 at the end) 等等(请注意末尾的+01)

In my report, I have: 在我的报告中,我有:

new SimpleDateFormat("HH:mm", $P{REPORT_LOCALE}).format($F{start_date}); new SimpleDateFormat(“ HH:mm”,$ P {REPORT_LOCALE})。format($ F {start_date});

However, for example, for "2015-03-02 11:45:00+01" I don't get 12:45 shown, I get 11:45. 但是,例如,对于“ 2015-03-02 11:45:00 + 01”,我没有看到12:45,而是11:45。

Also, I need to sum-up the hours (they're intervals) and this gives me a 1hr (in this case) error. 另外,我需要总结小时数(它们是间隔时间),这给了我1小时(在这种情况下)错误。

Can anyone help me show the correct hour? 谁能帮我显示正确的时间?

Thanks! 谢谢!

SimpleDateFormat takes a Date , not a Calendar - which means it can't be provided the time zone in the value itself. SimpleDateFormat采用Date而不是Calendar这意味着不能在值本身中提供时区。

Assuming you need to stick with SimpleDateFormat (rather than using Joda Time or Java 8's java.time , for example) then you'll need to set the time zone on the SimpleDateFormat itself. 假设您需要坚持使用SimpleDateFormat (例如,而不是使用Joda Time或Java 8的java.time ),则需要在SimpleDateFormat本身上设置时区。 If you need to take the time zone from the data (rather than having a report-wide zone) then you'll need to call setTimeZone before formatting each value - but of course, you'll also need to make sure you've got the time zone in the value, and java.sql.Timestamp doesn't have any notion of a time zone, as far as I'm aware. 如果您需要从数据中获取时区(而不是具有报告范围的时区),则需要在格式化每个值之前调用setTimeZone但是,当然,您需要确保已获取据我所知,值中的时区和java.sql.Timestamp没有时区的任何概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM