How to manage timezone in jrxml?

I have a field which needs to be  printed with the current time as Hours: Minutes

for example:

Current time is Thu Jul 27 15:58:30 IST 2017
I have to print 15:58

I have tried as 

.

It is printing what I need . But the problem is with timezone. 
MySystem timezone is in UTC.
I need to change it to CET/CEST. (Please don't suggest to change it system side. I strictly need to do it from Jasper )

How I can do that?
Can anyone please help me to understand how to implement this?

Thanks in advance.


 

 

Pandu's picture
2
Joined: Oct 15 2014 - 6:58am
Last seen: 6 years 2 months ago

1 Answer:

Joda Time is the easiest way to do time zone manipulations on date time fields in Jasper Reports (at least until Java 8 is fully supported).

joda time download link:

http://joda-time.sourceforge.net/installation.html

For jasper-server, add the joda time jar file into:

YOUR-JASPER-DIRECTORY/WEB-INF/lib

You'll notice other jar files there as well. WIll require a server restart to take effect.

 

If you're just using IReport/Jasper Studio, you'll need to add the jar to the class path, something along the lines of

Tools-->Option-->Classpath-->Add JAR

 

 

The code reference will be something like; see the ref to the example field below? You'll probably be able to make a go of it after this example:

<textFieldExpression><![CDATA[new org.joda.time.DateTime($F{YOUR_DATE_FIELD}).withZone(org.joda.time.DateTimeZone.forID("UTC"))]]></textFieldExpression>
 
It may be easier to add this in through the expression editor in IReport/Jasper Studio.
 
let me know if you run into any issues
 
darth_fader's picture
Joined: Mar 7 2010 - 9:45pm
Last seen: 3 months 2 weeks ago
Feedback
randomness