Search code examples
javagroovysimpledateformatboomi

SimpleDateFormat mask for 2020-12-21T13:00:00.000+0000


A date/time value is stored in our server as UTC which is correct. But when the server queries the date, it converts it to the server local time zone which is not necessarily the time zone of the device that has initiated the query. I am trying to simply adjust the time, based upon input parameters, to return it to UTC so it can be returned to the application in UTC. But when I try to parse the date so I can adjust the time, I run into a mask error.

I am having difficulty getting the right mask for this format: 2020-12-21T13:00:00.000+0000

Input Value: 2021-01-28T12:30:00.000+0000

Attempted mask: yyyy-MM-dd'T'HH:mm:ss

Error: No signature of method: java.text.SimpleDateFormat.parse() is applicable for argument types: (java.util.Date) values: {Thu Jan 28 12:30:00 UTC 2021} (in groovy script); Caused by: No signature of method: java.text.SimpleDateFormat.parse() is applicable for argument types: (java.util.Date) values: {Thu Jan 28 12:30:00 UTC 2021}

Code:

import java.util.GregorianCalendar; 
import java.util.Calendar; 
import java.util.Date; 
import java.text.SimpleDateFormat;

SimpleDateFormat inDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
SimpleDateFormat outDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
int minutesToAdd = (Hours * 60) + Minutes ;  
Calendar C = Calendar.getInstance();
java.util.Date D = inDate.parse(InputDate);
if (D!='')
     {
      C.setTime(D);
      C.add(Calendar.MINUTE, minutesToAdd);
      OutputDate=outDate.format(C.getTime());
     }
else
     {
      OutputDate = ''
     }

Any suggestions would be appreciated.


Solution

  • As cfrick suspected, the value being passed into the Groovy script from Boomi was of type java.util.Date and thus no parsing was needed.

    TY