iReport:如何根据法语区域设置格式化日期 [英] iReport: How to format date based on French locale
问题描述
我在 iReport中格式化日期有问题
我的电脑我将语言环境语言配置为法语但是当 iReport 生成报告时,我发现使用英语区域设置形成日期。
这里有几个我的 jrxml 文件中的代码:
< band height = 41splitType =Stretch>
< textField pattern =dd / MM / yyyy h.mm a>
< reportElement uuid =fb711e77-c949-4a99-9b52-109aae00c8edx =87y =19width =100height =20/>
< textElement />
< textFieldExpression><![CDATA [$ P {datenow}]]>< / textFieldExpression>
< / textField>
< staticText>
< reportElement uuid =51fb76a0-829e-4c36-b474-3ff9c7d4c239x =41y =19width =48height =20/>
< textElement>
< font isBold =trueisItalic =true/>
< / textElement>
< text><![CDATA [Fes Le:]]>< / text>
< / staticText>
< / band>
以下是我的显示方式: Fri Sep 28 09:59:00
我的目标格式是: vendredi 28 septembre 2012 09:59
(法语)
你有什么想法吗?
您的问题重复参数。
Map< String,Object> params = new HashMap< String,Object>();
params.put(JRParameter.REPORT_LOCALE,Locale.FRENCH);
JasperFillManager.fillReportToFile(compiledReportName,params);
使用此代码生成的报告结果相同。
工作样本 jrxml 文件:
<?xml version =1.0encoding =UTF-8?>
< jasperReport ... whenNoDataType =AllSectionsNoDetail...>
< parameter name =dateclass =java.util.DateisForPrompting =false>
< defaultValueExpression><![CDATA [new Date()]]>< / defaultValueExpression>
< /参数>
< title>
< band height =50>
< textField pattern =EEEEE dd MMMMM yyyy>
< reportElement x =200y =11width =228height =20/>
< textElement />
< textFieldExpression><![CDATA [$ P {date}]]>< / textFieldExpression>
< / textField>
< / band>
< / title>
< / jasperReport>
Java代码:
Map< String,Object> params = new HashMap< String,Object>();
params.put(date,new Date());
params.put(JRParameter.REPORT_LOCALE,Locale.FRENCH);
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,params,connection);
JasperExportManager.exportReportToPdfFile(jasperPrint,outputFile);
结果为:
I have a problem with formatting date in iReport
An my pc I configured the locale language as French but when the iReport generate the reports I find the date formated with English locale.
Here is a few code from my jrxml file :
<band height="41" splitType="Stretch">
<textField pattern="dd/MM/yyyy h.mm a">
<reportElement uuid="fb711e77-c949-4a99-9b52-109aae00c8ed" x="87" y="19" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{datenow}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="51fb76a0-829e-4c36-b474-3ff9c7d4c239" x="41" y="19" width="48" height="20"/>
<textElement>
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Fes Le : ]]></text>
</staticText>
</band>
and here is how it is displayed for me: Fri Sep 28 09:59:00
My target format is: vendredi 28 septembre 2012 09:59
(in French)
Do you have any idea?
Your question duplicates How to change date format (month name) in iReport? and Setting REPORT_LOCALE in IReport? posts.
- For setting locale in iReport you should call dialog Options - Compilation and exectution (via iReport -> Tools -> Options menu).
For this textField:
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
The result will be:
Note: It's works only for preview in iReport.
- For Java application you can set
JRParameter.REPORT_LOCALE
parameter.
Map<String, Object> params = new HashMap<String, Object>();
params.put(JRParameter.REPORT_LOCALE, Locale.FRENCH);
JasperFillManager.fillReportToFile(compiledReportName, params);
The result will be the same for report generated with code like this.
The working sample, jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... whenNoDataType="AllSectionsNoDetail" ...>
<parameter name="date" class="java.util.Date" isForPrompting="false">
<defaultValueExpression><![CDATA[new Date()]]></defaultValueExpression>
</parameter>
<title>
<band height="50">
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="200" y="11" width="228" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
Java code:
Map<String, Object> params = new HashMap<String, Object>();
params.put("date", new Date());
params.put(JRParameter.REPORT_LOCALE, Locale.FRENCH);
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint, outputFile);
The result be:
这篇关于iReport:如何根据法语区域设置格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!