cancel
Showing results for 
Search instead for 
Did you mean: 

Need Groovy Script to convert the 1486146877214 to date format in yyyy-MM-dd HH:mm:ssZ

giridhar_vegi
Participant
0 Kudos

Hi Team,

I have requirement where i need to fetch the value from the exchange property dynamically and checking for the expiry of the date in Groovy. the sample value is "1486146877214 " .I am using the below groovy script. 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.text.SimpleDateFormat;

def Message processData(Message message) {
    // Get Properties
    map = message.getProperties();
    long certExpirydate = map.get("CertificateValidUntil");
    // Calculate Expiry
    long dateNow = System.currentTimeMillis();
    long dateDiff = certExpirydate - dateNow;
    def daysToExpire = TimeUnit.DAYS.convert(dateDiff, TimeUnit.MILLISECONDS);
    // Set Properties
    Date certExpirydateDate = new Date(certExpirydate);
    message.setProperty("daysToExpire", daysToExpire);
    message.setProperty("CertExpirydate", certExpirydateDate);
   return message;
}
 
But I am getting the below error
***
Error at line: 10
***
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '1486146877214 ' with class 'java.lang.String' to class 'long'. Can anybody please help  me to resolve this .
 
Regards
Santosh Vegi.

Accepted Solutions (0)

Answers (1)

Answers (1)

Andrzej_Filusz
Contributor
0 Kudos

Hello,

Could you please replace that line:

long certExpirydate = map.get("CertificateValidUntil");

with the following one:

long certExpirydate = Long.parseLong(map.get("CertificateValidUntil"));

BR,

Andrzej