date conversion from GMT to EST

Hi All,

I am trying to convert the date from GMT to EST , I am using 9.6 version

Example 2017-12-21 18:00:000Z to 2017-12-21T 13:00:00.0 05:00 can please let me know the best way to get the results

Thanks

Hi,

when you transform the first value to a Date-Object, you can use the Built-In service pub.date:formatDate to get the value in the timezone specified.

Please note that using the abbrevations for timezone codes is deprecated due to ambiguosity.
Better use the numeric offset [+|-]xx:yy instead. Unfortunaley Java omits the colon separator between hours and minutes which leads to issues when using such values in XML fields defined as xsd:datetime-type.

Regards,
Holger

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

Hi Percio,

the ISO8601-Timezone pattern has been introduced with Java 7.

Should be working in webMethods 9.x and newer.

Thanks for pointing the link to Oracle documentation.

Regards,
Holger

You’re welcome. I have a 9.6 instance on my laptop and it came with Java 7 so S S should be able to use XXX.

Percio

1 Like