victorlizonglin Posted August 15, 2018 Share Posted August 15, 2018 In java code, I use String dateStr = "08/14/2018 23:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date dateTmp = dateFormat.parse(dateStr); DateFormat formatterUTC = new SimpleDateFormat("MM/dd/yyyy HH:mm"); formatterUTC.setTimeZone(TimeZone.getTimeZone("America/New_York")); System.out.println(formatterUTC.format(dateTmp));[/code]It is works perfectly to convert a time to EsternTime, but how could I do the same thing on JasperReport? I create some variables for that like "new SimpleDateFormat("MM/dd/yyyy HH:mm").setTimeZone(TimeZone.getTimeZone("UTC"))" but the return type is void which mean I cant use that in expression.Anyone know how to deal with that? I appricate it Link to comment Share on other sites More sharing options...
Solution victorlizonglin Posted August 16, 2018 Author Solution Share Posted August 16, 2018 OK, nobody answer that, then I found the solution.-----------------------------------------Step 1: Create the Parameter1, the class is "java.text.DateFormat" $P{REPORT_FORMAT_FACTORY}.createDateFormat("MM/dd/yyyy HH:mm",$P{REPORT_LOCALE}, TimeZone.getTimeZone("UTC"))[/code]-----------------------------------------Step 2: Create the Parameter2, the class is "java.text.DateFormat"$P{REPORT_FORMAT_FACTORY}.createDateFormat("MM/dd/yyyy HH:mm",$P{REPORT_LOCALE}, TimeZone.getTimeZone("America/New_York"))[/code]-----------------------------------------Step 3: Create the variable, the class is "java.util.Date"$P{Parameter1}.parse($F{dateStr}.toString())[/code]-----------------------------------------Step 4: Modified the detail you want to show in table or report$P{Parameter2}.format($V{variable})[/code]-----------------------------------------Then you got the date. Link to comment Share on other sites More sharing options...
riodavid Posted August 17, 2018 Share Posted August 17, 2018 Zonglin you are a genius. 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