Jump to content
We've recently updated our Privacy Statement, available here ×

How to convert the time(UTC) to EasternTime


victorlizonglin
Go to solution Solved by victorlizonglin,

Recommended Posts

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

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...