I had a similar requirement a while ago so I wrote my own version of dateTimeFormat that also takes in the desired timezone as input. Here’s the code:
IDataCursor cursor = pipeline.getCursor();
String inString = IDataUtil.getString( cursor, "inString" );
String currentPattern = IDataUtil.getString( cursor, "currentPattern" );
String newPattern = IDataUtil.getString( cursor, "newPattern" );
String timezone = IDataUtil.getString( cursor, "timezone" );
SimpleDateFormat format = new SimpleDateFormat( currentPattern );
format.setLenient(false);
Date currentDate;
try
{
currentDate = format.parse(inString );
}
catch( Throwable t )
{
cursor.destroy();
throw new ServiceException(t);
}
format = new SimpleDateFormat(newPattern);
format.setTimeZone(TimeZone.getTimeZone(timezone));
String value = format.format(currentDate);
IDataUtil.put(cursor, "value", value);
cursor.destroy();
By the way, Java does support time zone offsets in the ISO8601 format now, including the colon. Check out: SimpleDateFormat (Java Platform SE 8 )
Using your example, you could call the service with the following inputs:
inString: 2017-12-21T13:00:00.000-00:00
currentPattern: yyyy-MM-dd’T’HH:mm:ss.SSSXXX
newPattern: yyyy-MM-dd’T’HH:mm:ss.SSSXXX
timezone: GMT-5
And the service returns: 2017-12-21T08:00:00.000-05:00
Good luck,
Percio
#webMethods#Flow-and-Java-services#Integration-Server-and-ESB