开发者

date appears one day prior to what is programmed in JasperServer

I posted this on the JasperServer forums, but I've had better luck on StackOverflow generally. Please help if you can.

My biggest single gripe about JasperServer is that it flat out behaves differently than JasperReport (specifically, reports developed in iReport).

The problem I'm seeing now is that dates are displayed as one day prior (in fact, exactly 4 hours prior) to the date put into the parameter.

This is what I put into the default value expression of the JRXML:

 ((new Date().getMonth() / 3) + 1 == 1)? new Date(new Date().getYear(), 0, 1) :

((new Date().getMonth() / 3) + 1 开发者_Python百科== 2)? new Date(new Date().getYear(), 3, 1) :

((new Date().getMonth() / 3) + 1 == 3)? new Date(new Date().getYear(), 6, 1) :

new Date(new Date().getYear(), 9, 1) 

This code works to correctly calculate the beginning of the quarter from within the default value expression of JasperReports. When i run this through iReport, i see no problem whatsoever. For any reports I've run in this quarter, i'm seeing July 1, 2010 as the start date.

When I modify the JRXML to account for the "repo:subreport_name" format of JasperServer and run this report and have JasperServer email the output to me I get a different result:

6/30/10 8:00 PM

This seems like a bug to me.


It looks like a time zone problem.

It seems to be printing your date 4 hours in the past.

Where is the server you are running from?

Can you check it's time zone?

For example take a look at this code. It will print a different day and month depending on the time zone.

Date date = ((new Date().getMonth() / 3) + 1 == 1) ? new Date(new Date().getYear(), 0, 1)
    :((new Date().getMonth() / 3) + 1 == 2) ? new Date(new Date().getYear(), 3, 1) 
    :((new Date().getMonth() / 3) + 1 == 3) ? new Date(new Date().getYear(), 6, 1) 
    :new Date(new Date().getYear(), 9, 1);
System.out.println(date);

Outputs: Thu Jul 01 00:00:00 BST 2010

TimeZone.setDefault(TimeZone.getTimeZone("PST"));
System.out.println(date);

Outputs Wed Jun 30 16:00:00 PDT 2010 with the same date.

Bit of hack but you could set the hour to later in the day to guarantee it gets the right day for example:

new Date(new Date().getYear(), 3, 1,23,59); 

Edit:

The correct way to set the time zone your jasper report is through the datasource.

Just call the setTimeZone() method on your data source before passing to your report for example

mydatasource.setTimeZone(TimeZone.getTimeZone("BST"));

The problem is the server see no time zone is set so just uses the default causing your date error.


Straight from the horse's mouth:

http://jasperforge.org/plugins/espforum/view.php?group_id=112&forumid=107&topicid=77176

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜