pvelan Posted October 21, 2011 Share Posted October 21, 2011 All,I am getting the date as '" 2011014 145300 " in XML, but I need to display the date as 10/14/2011. Could someone let me know what is the best way to do this?Thanks. Link to comment Share on other sites More sharing options...
iamwoodyjones Posted October 21, 2011 Share Posted October 21, 2011 I can tell you of _a_ way but it might not be the best. What I would do is set a text field expression to use a date and then I would set the expression to something like:new java.text.SimpleDateFormat(" ").parse(" ")The first " " would be the pattern to create the date and the second " " would your string to create the date from.----Now, if you're using the XMLDataSource, though, skip all of what I just said and instead just set your parameter of XML_DATE_PATTERN to your pattern and you should be good.From:http://jasperreports.sourceforge.net/sample.reference/xmldatasource/index.html Link to comment Share on other sites More sharing options...
pvelan Posted October 21, 2011 Author Share Posted October 21, 2011 Hello,Thanks for your suggestions, but I am getting the following error...Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : new java.text.SimpleDateFormat("MM/dd/yyyy").parse($F{startDate}) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:195) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:589) at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:557) at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:929) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:383) at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:368) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:258) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:499) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2036) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:760) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:270) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864) at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:613) at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59) at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:205) at java.lang.Thread.run(Thread.java:662) Caused by: java.text.ParseException: Unparseable date: "20111014 145300" at java.text.DateFormat.parse(DateFormat.java:337) I tried substring option to just take "20111014". Even this gives the same error.When i want to preview, how do I set "XML_DATE_PATTERN" in ireport?Thanks Link to comment Share on other sites More sharing options...
iamwoodyjones Posted October 21, 2011 Share Posted October 21, 2011 If you are using the XML Data Source then please just follow the web link I posted above and set your XML_DATE_PATTERN paramater with a good default value and you should start getting dates returned when your xml is parsed. Really, that's the best way to set the date pattern globally for your xml data source.Now, if you have multiple types of date patterns for your xml then just setting XML_DATE_PATTERN isn't going to do you much good. Your problem above is that you're trying to set the date format to what you want in your report. You don't want to do that. Instead, you need to set your date format to what you're given in your xml file for parsing into the java.lang.date.I don't know what kind of date string you have above but if I wanted to parse from xml the date string of 20111014 which would be 2011, Oct, 14th then I would do this:new java.text.SimpleDateFormat("yyyyMMdd").parse("20111014");Once you have it parsing into a valid java.lang.date, then you can use IReport to define your date mask and be on your merry way. Link to comment Share on other sites More sharing options...
pvelan Posted October 21, 2011 Author Share Posted October 21, 2011 Thank you. After sending in the correct format, issue is resolved and thru ireports i could apply the correct mask. Link to comment Share on other sites More sharing options...
iamwoodyjones Posted October 21, 2011 Share Posted October 21, 2011 Great news. Glad I could help you out. Spread the love on the forums! :-) Link to comment Share on other sites More sharing options...
criztiandiaz Posted May 7, 2015 Share Posted May 7, 2015 nesecito poner el formato de fecha en dd-mm-yyyy lo tengo yyyy-mm-ddy en pattern cambio el formato pero no lo guarda nose que hacer ayuda gracias 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