javaiso8583jposopeniso8583.net

How to format Java utill date for ISO m8583?


I am using the following function that returns a formatted string date:

private static String formatDate(String format) {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat(format);

    String strDate = sdf.format(date);
    return strDate;
}

This function returns for example if i call it using the following format:

System.out.println(formatDate("MMYYHHMMSS"));

it prints: 04130904803

When I use the above date to create an ISO message eg.

// Create ISO Message
    ISOMsg isoMsg = new ISOMsg();
    isoMsg.setPackager(packager);
    isoMsg.setMTI("0200");
            isoMsg.set(2, "100002");
    isoMsg.set(3, "201234");
    isoMsg.set(7, "04130904803");
    isoMsg.set(11, "123456");
    isoMsg.set(44, "A5DFGR");
    isoMsg.set(105, "ABCDEFGHIJ 1234567890");


    // Get and print the output result
    byte[] data = isoMsg.pack();

            unpackISO(new String(data));

I get the following error: =>Error: error packing field 7 But when I remove the preceding zero of date in field 7, I works fine. What date format should i use in java to format the date? Help!


Solution

  • You use ISODate.getDateTime(Date d) or ISODate.getDateTime(Date, TimeZone).

    See http://jpos.org/doc/javadoc/org/jpos/iso/ISODate.html