【发布时间】:2018-05-02 15:44:22
【问题描述】:
我不确定为什么会发生这种情况,但时区和所有设置都是正确的,但数据库中的日期时间没有反映在报告中并显示不同的内容。
注意:此 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 数据库中:
18 年 1 月 2 日 11.22.09 下午
日期在 excel 报告中
2018 年 1 月 2 日下午 6:22:09
这有什么问题我真的不知道。
但从 excel 报告的角度以及 db 的角度来看,时区是正确的。 并且时区仅为“美国/东部”。
出现错误的列是这些字段:
inspectionQCCompleteDate,inspectionCompleteDate
请有人帮我解决这个问题。
【问题讨论】:
-
@AlexK 我删除了多余的代码并在底部添加了更多描述。
标签: java datetime timezone jasper-reports