Format dates and numbers in iReport
To set up the format of a report and display a date at the top of it every time it's run:
- Download a report from Aspen.
- Open the file in iReport.
- Click the F icon in the toolbar at the top of the page.
- Click at the top of the report where you would like the date to appear. Drag the mouse to create a new field.
- Right-click on the newly created field, and select Properties.
- Click the Text Field tab.
- The Text Field Expression Class will be set to java.lang.String. To display the correct Object type, change it to java.util.Date.
- Close the Properties pop-up.
- Right-click on the text field, and select Edit Expression.
- In the Expression editor, type the following:
new java.util.Date(System.currentTimeMillis())
- Click Apply to save the changes. This returns the system’s current time in milliseconds, which can be made into a date object with the new java.util.Date constructor.
To format the date and time:
- Right-click on the newly created field, and select Properties.
- Click the Text Field tab.
- In the Pattern field, type the date string pattern for the desired date format:
-
Date String Pattern for January 1, 2021
Output
None
Thur Jan 01 00:00:01 EDT 2021
M/d/yy
1/1/21
MM/dd/
01/01/2021
MMM. dd,
Jan. 01, 2021
MMMM
January 01, 2021
yyyy G
2021 AD
- Time is also considered part of the date. To display the time the report was run, type the desired time string pattern:
-
Time String Pattern for 4:45 PM Eastern Daylight Time
Output
H:mm
4:45
Hh:mm:
04:45:23
H:mm a
4:45 PM
Hh:mm: a z
04:45 PM EST
Hh:mm: a
04:45 PM Eastern Daylight Time
Letter String Pattern
Representation
G
Era (AD/BC)
y
Year
M
Month in year
d
Day in month
a
AM/PM
H
Hour of the day (24-hour time)
h
Hour of the day (12-hour time)
m
Minute of the hour
s
Second of the minute
S
Milliseconds
z
Time zone
To format a number:
- Create a new text field. In the toolbar at the top, click the F icon.
- Right-click on the newly created field, and select Properties.
- Click the Text Field tab.
- In the Text Field Expression Class field, enter a number expression:
- If the value is an integer, set it to java.lang.Integer.
- If the value is a double (a number with a decimal), set it to java.lang.Double.
- In the Pattern field, type the string for how you want the number to appear.
- 0 = the number displays regardless of value
- # = the number displays if it not zero
-
Number String Pattern for 000003.458695000
Representation
None
3.458695000
0.00
3.46
##0.00
3.46
##0
3
##0.00##
3.458
#.0000000000
3.458695000
#.000#######
3.458695
Note: iReport always displays numbers to the left of the decimal point, as long as they are not zeros. 0.00 does not display the number 321 as 1.00.
Exception: An improper pattern will throw an Illegal Argument Exception. When MdMd or #0#0 is entered for a pattern, an error will occur.