Skip to Content
0
Jan 13, 2023 at 11:26 AM

[SAP CPI]: Groovy date parsing issue

840 Views Last edit Jan 13, 2023 at 11:27 AM 2 rev

Hi Experts,

My requirement is to send the date from yyyy-MM-dd'T'HH:mm:ss.SSSXXX to yyyyMMddHHmmssSSS.

But sometimes, the data is received without milliseconds, due to this my groovy script is failing with an unparsable date issue.

Works when the date is in 2022-11-30T11:45:53.243+01:00 format

Fails when the date is in 2022-11-30T11:45:53+01:00 format

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.*
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
def Message processData(Message message) {

    String mod_time = message.getProperty("PL_ModificationTime");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
    Date MOD = sdf.parse(mod_time);

    message.setProperty("ModificationTime", MOD.format("yyyyMMddHHmmssSSS"));

	return message;
}

Any leads to fix this issue in the below groovy script will be really helpful.

Regards,

Pavan