Jasper reports 如何设置REPORT\u TIME\u ZONE参数的值?

Jasper reports 如何设置REPORT\u TIME\u ZONE参数的值?,jasper-reports,Jasper Reports,如何使用report\u time\u zone内置参数设置报表的时区?借助代码可以轻松地将时区传递给报表。例如,对于Java: Map<String, Object> params = new HashMap<>(); params.put(JRParameter.REPORT_TIME_ZONE, TimeZone.getTimeZone("Europe/London")); JasperPrint jasperPrint = JasperFillManager.f

如何使用report\u time\u zone内置参数设置报表的时区?

借助代码可以轻松地将时区传递给报表。例如,对于Java:

Map<String, Object> params = new HashMap<>();
params.put(JRParameter.REPORT_TIME_ZONE, TimeZone.getTimeZone("Europe/London"));

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
在本例中,我借助伪变量通过参数映射更改了参数的值:

$P{REPORT_PARAMETERS_MAP}.put("REPORT_TIME_ZONE", java.util.TimeZone.getTimeZone("Europe/Moscow"))

我在报告中设置了假变量。但是报表数据没有按照变量1中设置的时区值填充。您使用什么表达式来显示时间?2您使用的JR版本是什么?模板版本似乎与版本7.5.0不兼容。我使用带有模式dd.MM.yyyy的表达式$F{fieldname}来显示日期。
<?xml version="1.0" encoding="UTF-8"?>
<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 sample" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <variable name="fake" class="java.util.TimeZone">
        <variableExpression><![CDATA[java.util.TimeZone.getDefault()]]></variableExpression>
        <initialValueExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.put("REPORT_TIME_ZONE", java.util.TimeZone.getTimeZone("Europe/Moscow"))]]> </initialValueExpression>
    </variable>
    <title>
        <band height="60">
            <textField>
                <reportElement x="0" y="30" width="100" height="30"/>
                <textFieldExpression><![CDATA[new Date()]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>
$P{REPORT_PARAMETERS_MAP}.put("REPORT_TIME_ZONE", java.util.TimeZone.getTimeZone("Europe/Moscow"))