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

How to print data as per users time zone


siladitya.dash

Recommended Posts

Could someone please help me out on printing data as per user timezone. We have a scenario where the user will pass the timezone and based upon that the value should return. I found the way to modify the date parameters as per user passed time zone and get the resule from databse. But after that how should I write the data in there time zone. Do I need to convert individual date columns to be printed on there time zone or any other way is there to convert once as per there time zone and print all values.

Let me tell you we trying to implement this on existing reports, so we are looking for a process for least changes.

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Below jrxml would provide you with the selected timezone current date/time based on a parameter.

some timezone id's that can be passed as a parameter value :

Pacific/ApiaPacific/MidwayPacific/NiuePacific/Pago_PagoPacific/SamoaUS/SamoaAmerica/AdakAmerica/AtkaEtc/GMT+10[/code]

try using your field values with the selected timezone expressions and see if it works

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  --><!-- 2017-02-23T13:22:58 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="timezone" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="544f695c-dad6-4924-a4f2-7555ee097887">    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>    <parameter name="TimezoneSelector" class="java.lang.String">        <defaultValueExpression><![CDATA["America/Anchorage"]]></defaultValueExpression>    </parameter>    <queryString>        <![CDATA[select to_date('12/30/2015 3:39:26 PM', 'MM/dd/yyyy hh:mi:ss AM') my_datefrom dual]]>    </queryString>    <field name="MY_DATE" class="java.lang.String"/>    <background>        <band splitType="Stretch"/>    </background>    <detail>        <band height="180" splitType="Stretch">            <textField pattern="MM/dd/yyyy">                <reportElement x="380" y="30" width="100" height="30" uuid="aebe7a58-592b-4482-826b-702a4702cb8f"/>                <textFieldExpression><![CDATA[DATE(java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone($P{TimezoneSelector})).get(java.util.Calendar.YEAR),    java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone($P{TimezoneSelector})).get(java.util.Calendar.MONTH)+1,    java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone($P{TimezoneSelector})).get(java.util.Calendar.DATE))]]></textFieldExpression>            </textField>            <textField>                <reportElement x="180" y="30" width="100" height="30" uuid="a1157501-937d-4cd0-a703-90983ebf160b"/>                <textFieldExpression><![CDATA[$P{TimezoneSelector}]]></textFieldExpression>            </textField>            <textField>                <reportElement x="580" y="30" width="100" height="30" uuid="316bd2af-778f-43e8-b2db-0c323915ba92"/>                <textFieldExpression><![CDATA[TIME(java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone($P{TimezoneSelector})).get(java.util.Calendar.HOUR_OF_DAY),java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone($P{TimezoneSelector})).get(java.util.Calendar.MINUTE),java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone($P{TimezoneSelector})).get(java.util.Calendar.SECOND),"hh:mm:ss a")]]></textFieldExpression>            </textField>            <staticText>                <reportElement x="180" y="0" width="100" height="30" uuid="6a3b238f-ed56-4728-96dd-677e57bcc89a"/>                <textElement>                    <font isBold="true"/>                </textElement>                <text><![CDATA[selected timezone]]></text>            </staticText>            <staticText>                <reportElement x="580" y="0" width="100" height="30" uuid="8b6a9891-fe7b-4653-9ca7-925805f19cb5"/>                <textElement>                    <font isBold="true"/>                </textElement>                <text><![CDATA[selected timezone time]]></text>            </staticText>            <staticText>                <reportElement x="380" y="0" width="100" height="30" uuid="6166e4ff-8c8e-402b-b8ac-75c1e15cf50d"/>                <textElement>                    <font isBold="true"/>                </textElement>                <text><![CDATA[selected timezone date]]></text>            </staticText>            <textField pattern="MM/dd/yyyy">                <reportElement x="380" y="150" width="100" height="30" uuid="6ce3bfaf-184e-4926-aa9e-05633e0dfa46"/>                <textFieldExpression><![CDATA[new Date()]]></textFieldExpression>            </textField>            <textField>                <reportElement x="180" y="150" width="100" height="30" uuid="d3f1919c-b04e-4c41-ac3b-290dd97f48aa"/>                <textFieldExpression><![CDATA[$P{REPORT_TIME_ZONE}.getID()]]></textFieldExpression>            </textField>            <textField pattern="hh:mm:ss a">                <reportElement x="580" y="150" width="100" height="30" uuid="2a3158a1-dc35-422b-8837-fd3c07935e74"/>                <textFieldExpression><![CDATA[new Date()]]></textFieldExpression>            </textField>            <staticText>                <reportElement x="180" y="120" width="100" height="30" uuid="1606f8e7-3447-4543-9a16-a2d8dd58c08c"/>                <textElement>                    <font isBold="true"/>                </textElement>                <text><![CDATA[current timezone]]></text>            </staticText>            <staticText>                <reportElement x="580" y="120" width="100" height="30" uuid="43cffca4-84b7-4cd7-800b-47dac4240739"/>                <textElement>                    <font isBold="true"/>                </textElement>                <text><![CDATA[current timezone time]]></text>            </staticText>            <staticText>                <reportElement x="380" y="120" width="100" height="30" uuid="3e8cca4a-2476-47a2-a2bf-443a338bc249"/>                <textElement>                    <font isBold="true"/>                </textElement>                <text><![CDATA[current timezone date]]></text>            </staticText>        </band>    </detail></jasperReport>[/code]

 

Link to comment
Share on other sites

  • 2 weeks later...

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...