Stop Timezone conversion for one field in report

0

I have a report that has several dates on it.  The dates are stored in the database in UTC format.  I have the report converting UTC to local report time, however, one of the dates is date-of-birth.  The database field is yyyy-mm-dd 00:00:00.  When the DOB is displayed on the report the date/time is adjusted -4, -5 or -6 hours and displays as the previous day.

How can I keep the DOB from being adjusted to local time?

eddie_4's picture
Joined: Apr 25 2017 - 8:18am
Last seen: 5 days 11 hours ago

Let me know if you still have issues

darth_fader - 6 days 12 hours ago

Thanks for your response.  I'm still a noob in iReports and although I know C#, Javascript and a slew of other languages, java isn't in my back of tricks.

Would I put code in the field def on the report?  Right now, I'm just using a pattern to format the data.

Will I need to add another library for the Joda-Time libraries?  

Sorry to be a pain, just not up to speed on the architecture of adding code to a specific field.

eddie_4 - 6 days 13 hours ago

This solution should get you through it

darth_fader - 6 days 12 hours ago
show 1 more...

That answer helped me.  Thank you.  The date is now correct.  However it is ignoring the pattern.  I have MM/dd/yyyy for the pattern but the report is formatting as yyyy-MM-ddT00:00:00.

 

<textField pattern="MM/dd/yyyy" isBlankWhenNull="true">
 
    <reportElement x="123" y="0" width="88" height="20" uuid="40bfec19-25c5-4807-801f-464034799729"/>
 
    <textElement>     <font fontName="Arial" isBold="false"/>    </textElement>
 
    <textFieldExpression><![CDATA[new org.joda.time.DateTime($F{dob}).withZone(org.joda.time.DateTimeZone.forID("UTC"))]]></textFieldExpression>
 
   </textField>

eddie_4 - 6 days 10 hours ago

1 Answer:

1

For jasper-server, add it 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: 2 days 18 hours ago
Feedback
randomness