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:

  1. Download a report from Aspen.
  2. Open the file in iReport.
  3. Click the F icon in the toolbar at the top of the page.
  4. Click at the top of the report where you would like the date to appear. Drag the mouse to create a new field.
  5. Right-click on the newly created field, and select Properties.
  6. Click the Text Field tab.
  7. The Text Field Expression Class will be set to java.lang.String. To display the correct Object type, change it to java.util.Date.
  8. Close the Properties pop-up.
  9. Right-click on the text field, and select Edit Expression.
  10. In the Expression editor, type the following:

new java.util.Date(System.currentTimeMillis())

  1. 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:

  1. Right-click on the newly created field, and select Properties.
  2. Click the Text Field tab.
  3. In the Pattern field, type the date string pattern for the desired date format:
  4. 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

  1. Time is also considered part of the date. To display the time the report was run, type the desired time string pattern:
  2. 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:

  1. Create a new text field. In the toolbar at the top, click the F icon.
  2. Right-click on the newly created field, and select Properties.
  3. Click the Text Field tab.
  4. 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.
  1. In the Pattern field, type the string for how you want the number to appear.
  2. 0 = the number displays regardless of value
  3. # = the number displays if it not zero
  1. 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.