cancel
Showing results for 
Search instead for 
Did you mean: 

UDF require to convert Time Zone from EST to PDT

Former Member
0 Kudos

Hi Gurus,

  Request to help me to get a proper UDF for converting TimeZOne from EST to PDT.

  i have followed the below link by ENG

but getting below error

Can any one help me how to resolve this or please provide me any UDF which will help me out .

Appreciate your help.

Regards,

Yugandhar.

Accepted Solutions (0)

Answers (5)

Answers (5)

nikhil_bose
Active Contributor
0 Kudos

it might be a typo. can you remove empty spaces and lines above 'public string convertTimeZone'?

Regards,

Nikhil Bose

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Yugandhar,

Are you using UDF by referring to the blog of Eng, then can you please cross check whether you have imported the joda libraries correctly or not into your ESR.

Also, please share the code for which you are getting the error.

Regards

Former Member
0 Kudos

Hi Vishnu,

i have imported JODE libraries and added it to Archives .

Regards

Yugandhar

Former Member
0 Kudos

please find the below code which used

public String convertTimeZone(String Input_Timestamp, String Timestamp_format, String From_Timezone, String To_Timezone, Container container) throws StreamTransformationException{

LibraryMethod(title="convertTimeZone", description="Convert input time from one timezone to another", category="FL_DateTime", type=ExecutionType.SINGLE_VALUE)

public String convertTimeZone ( 

  Argument(title="Input_Timestamp")  String timestamp, 

  Parameter(title="Timestamp_format")  String format, 

  Parameter(title="From_Timezone")  String fromTZ, 

  Parameter(title="To_Timezone")  String toTZ, 

   Container container)

throws StreamTransformationException

  DateTimeFormatter formatter = DateTimeFormat.forPattern(format); 

  DateTimeZone originalTZ = DateTimeZone.forID(fromTZ); 

  DateTime fromDateTime = new DateTime(DateTime.parse(timestamp, formatter), originalTZ); 

  DateTime toDateTime = fromDateTime.withZone(DateTimeZone.forID(toTZ)); 

  return formatter.print(toDateTime); 

}

former_member186851
Active Contributor
0 Kudos

code seems to be fine.

Did you follow these steps

Prerequisite:

Download the library files for Joda-Time from Joda-Time's repository.

Import JAR file into an Imported Archive object.

Add Imported Archive in Archives Used section of Message Mapping or Function Library.

former_member186851
Active Contributor
0 Kudos

Please paste the code which you have declared?

Former Member
0 Kudos

Hi,

Seems that Issue with the function name/variable names that you have given. Please assign as convertTimeZone.

Also needs to add library files of Joda-times which is different with standard conversion.

Please also try with below logic:

<Library def><import java.util/text.*;>

Calendar timeDef = new GregorianCalendar();

int a1 =  DateFormat.SHORT;

int b1 =  DateFormat.SHORT;

String dtEST = DateFormat.getDateTimeInstance(a1,b1).format(timeDef.getTime())+" EST"; 

time.setTimeInMillis(timeDef.getTimeInMillis()- 60*60*3000);

String dtPST = DateFormat.getDateTimeInstance(a1,b1).format(timeDef.getTime())+" PST";

System.out.println(dtEST+"\n"+dtPST);

Regards,prasanth