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.

I have a view which returns dates with the following format:

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

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

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

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

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

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

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

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

etc (notice the +01 at the end)

In my report, I have:

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.

Also, I need to sum-up the hours (they're intervals) and this gives me a 1hr (in this case) error.

Can anyone help me show the correct hour?

Thanks!

Jon Skeet
people
quotationmark

SimpleDateFormat takes a Date, not a Calendar - which means it can't be provided the time zone in the value itself.

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. 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.

people

See more on this question at Stackoverflow