q16marvin Posted November 6, 2012 Share Posted November 6, 2012 hello,my query give me seconds (for example 120). know i want to display this in the format HH:mm:ss (00:02:00). How can i do this with ireport?i cant format it in the query because i want to display a sum of the seconds also in the format HH:mm:ssthank you! Link to comment Share on other sites More sharing options...
marianol Posted November 6, 2012 Share Posted November 6, 2012 I will get the SQL to give me the correct format, you can use something like this in postgres: SELECT TO_CHAR(yourSecondsField || ' second'::interval, 'HH24:MI:SS')That will convert yourSecondsField into a string with the HH:MM:SS format Link to comment Share on other sites More sharing options...
q16marvin Posted November 6, 2012 Author Share Posted November 6, 2012 yes of course, but then ireport is not able to build a sum over all times. Link to comment Share on other sites More sharing options...
marianol Posted November 6, 2012 Share Posted November 6, 2012 True :) So doing it in Java will be your friend, you can try something like: String.format("%d:%02d:%02d", mySeconds/3600, (mySeconds%3600)/60, (mySeconds%60)) Link to comment Share on other sites More sharing options...
q16marvin Posted November 7, 2012 Author Share Posted November 7, 2012 okay you mean this as expression for the field? but than i get this errors:Error filling print... Error evaluating expression : Source text : String.format("%d:%02d:%02d", $F{avg_call_duration}/3600, ($F{avg_call_duration}%3600)/60, ($F{avg_call_duration}%60)) Setting up the file resolver... net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : String.format("%d:%02d:%02d", $F{avg_call_duration}/3600, ($F{avg_call_duration}%3600)/60, ($F{avg_call_duration}%60)) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:203) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559) at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:884) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:425) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:406) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:257) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:457) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2037) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:771) Link to comment Share on other sites More sharing options...
shertage Posted November 7, 2012 Share Posted November 7, 2012 Hello,As alternative, we could use java.util.Date and TimeZone instances in the textfield expression to do the work:- set the textfield pattern as desired: "HH:mm:ss";- if the my_data field value is given in seconds, apply the following textfield expression:<textField pattern="HH:mm:ss"> ... <textFieldExpression><![CDATA[new java.util.Date($F{my_data} * 1000 - java.util.TimeZone.getDefault().getOffset($F{my_data} * 1000))]]></textFieldExpression> </textField>Regards,sanda Link to comment Share on other sites More sharing options...
marianol Posted November 7, 2012 Share Posted November 7, 2012 You need to use the full class in ireport "java.lang.String" anyway I think that the answer from below is more elegant. Link to comment Share on other sites More sharing options...
christosloizou Posted November 18, 2022 Share Posted November 18, 2022 Anyone found a solution here ? Link to comment Share on other sites More sharing options...
m_ilio Posted July 25 Share Posted July 25 This works for me:String.format("%02d:%02d:%02d", (int)($F{seconds}/3600),(int)(($F{seconds}%3600)/60),(int)($F{seconds}%60)) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now