我不确定为什么会发生这种情况,但时区和所有设置都是正确的,但是数据库中的日期时间并没有反映在报告上并显示出不同的内容。
注意:此excel报告将由jasper报告工具导出。
JRXML
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="groundingReport"
columnCount="1"
printOrder="Vertical"
orientation="Landscape"
pageWidth="3600"
pageHeight="842"
columnWidth="3600"
columnSpacing="0"
leftMargin="0"
rightMargin="0"
topMargin="0"
bottomMargin="0"
whenNoDataType="AllSectionsNoDetail"
isTitleNewPage="false"
isSummaryNewPage="false"
isIgnorePagination="true">
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<parameter name="SIMPLE_DATE_FORMAT_WITH_TIME_ZONE" isForPrompting="false" class="com.adesa.framework.report.util.SimpleDateFormatWithTimeZone">
<defaultValueExpression ><![CDATA[new com.adesa.framework.report.util.SimpleDateFormatWithTimeZone("MM/dd/yyyy HH:mm:ss a", TimeZone.getTimeZone("US/Eastern"))]]></defaultValueExpression>
</parameter>
<parameter name="INSPECTION_PROVIDER" isForPrompting="false" class="java.lang.String"/>
<field name="inspectionOrderedDate" class="java.sql.Timestamp"/>
<field name="inspectionQCCompleteDate" class="java.sql.Timestamp"/>
<field name="inspectionCompleteDate" class="java.sql.Timestamp"/>
<field name="inspectionProvider" class="java.lang.String"/>
<variable name="Test" class="java.lang.String" resetType="Report" calculation="Nothing">
</variable>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="50" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="75" isSplitAllowed="true" >
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textFieldExpression class="java.lang.String"><![CDATA[$P{JRXML_DT_FRM}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="162"
y="30"
width="162"
height="15"
key="textField-40"
stretchType="RelativeToTallestObject"
positionType="Float"
isPrintWhenDetailOverflows="true"/>
<box> <pen lineWidth="0.0"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<textElement verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{JRXML_DT_TO}]]></textFieldExpression>
</textField>
<staticText>
<textElement textAlignment="Left" verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection Provider]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{INSPECTION_PROVIDER}.equals("AUTOVIN LIVE") ? "AutoVIN Live" : $P{INSPECTION_PROVIDER}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="24" isSplitAllowed="true" >
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection Provider]]></text>
</staticText>
<staticText>
<reportElement
mode="Opaque"
x="162"
y="0"
width="162"
height="24"
backcolor="#CCCCFF"
key="staticText-2"/>
<box> <pen lineWidth="0.0"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[VIN]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection Ordered]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection Complete]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[ Days to QC Complete]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection Incomplete]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Incomplete Inspection Reason]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[QC Complete]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection Not Inspected ]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection ID]]></text>
</staticText>
<staticText>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica-Bold" isBold="true"/>
</textElement>
<text><![CDATA[Inspection Cancelled]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="15" isSplitAllowed="true" >
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{inspectionProvider}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{vin}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="MM/dd/yyyy hh:mm:ss a" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement textAlignment="Center" verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a").parse($P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.format($F{inspectionOrderedDate}))]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="MM/dd/yyyy hh:mm:ss a" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement textAlignment="Center" verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a").parse($P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.format($F{inspectionCompleteDate}))]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="###0;-###0" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement textAlignment="Center" verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{daysToQCComplete} != null ? Integer.valueOf($F{daysToQCComplete}): null]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.format($F{inspectionIncompleteDate})]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{incompleteInspectionReason}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="MM/dd/yyyy hh:mm:ss a" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<textElement textAlignment="Center" verticalAlignment="Bottom">
<font fontName="Arial" pdfFontName="Helvetica" isItalic="false"/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a").parse($P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.format($F{inspectionQCCompleteDate}))]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
日期在oracle db中:
02-JAN-18 11.22.09 PM
日期在excel reoprt中
1/2/2018 6:22:09 PM
我真的不知道这有什么问题。
但是从excel报告的角度来看,时区也是正确的。 而且时区只是“美国/东方”。
出错的列是这些字段:
请某人帮我解决这个问题。inspectionQCCompleteDate,inspectionCompleteDate
答案 0 :(得分:0)
要解决日期时间差异,请为 inspectionQCCompleteDate &amp ;;定义 textFieldExpression 。 jrxml 中的 inspectionCompleteDate 列如下:
<textFieldExpression class="java.util.Date">
<![CDATA[$P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.parse($P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.format($F{inspectionQCCompleteDate}))]]>
</textFieldExpression>
<textFieldExpression class="java.util.Date">
<![CDATA[$P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.parse($P{SIMPLE_DATE_FORMAT_WITH_TIME_ZONE}.format($F{inspectionCompleteDate}))]]>
</textFieldExpression>