on ‎2011 Jul 14 7:06 AM
Hi All,
I have an input date time iIhave to convert this to UTC for example
if its 1994-11-05T08:15:30-05:00 it has to be converted to 1994-11-05T13:15:30Z
Thanks
Request clarification before answering.
CHK THIS:
input will be var1
execution type: single value..
String date1="";
String date2="";
String date3="";
date1=var1.substring(0,10);
date2=var1.substring(11,19);
date3=date1+"T"+date2+"Z";
return date3;
Mapping:
Date -> UDF -> Output Date
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kran,
I have tested this code.
Here you go for your exact requirement.
Your input should be only one to this UDF p_localDateTime
And do use substring to provide the input to dd-MM-yyyy HH:mm:ss format before passing it to the UDF.
Example : 1994-11-05T08:15:30-05:00 Use substring and concat to convert it to dd-MM-yyyy HH:mm:ss format 1994-11-05 08:15:30
Also in Function tab of message mapping editor import the additional thing.
java.text.SimpleDateFormat
java.util.Date
public String converttoUTC(String p_localDateTime, Container container) throws StreamTransformationException{
String lv_dateFormateInUTC="";//Will hold the final converted date
Date lv_localDate = null;
String lv_localTimeZone ="";
SimpleDateFormat lv_formatter;
SimpleDateFormat lv_parser;
//create a new Date object using the timezone of the specified city
lv_parser = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
lv_parser.setTimeZone(TimeZone.getTimeZone("EST"));
try
{
lv_localDate = lv_parser.parse(p_localDateTime);
}
catch (java.text.ParseException e)
{
}
//Set output format prints "2007/10/25 18:35:07 EDT(-0400)"
lv_formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z'('Z')'");
lv_formatter.setTimeZone(TimeZone.getTimeZone(lv_localTimeZone));
//Convert the date from the local timezone to UTC timezone
lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
lv_dateFormateInUTC = lv_formatter.format(lv_localDate);
return lv_dateFormateInUTC;
}
Hi I tried but iam getting this error:
'class' or 'interface' expected ^
Iam using the code as below:
Imports java.util.Date;java.text.SimpleDateFormat;
public String UTC(String p_localDateTime ,Container container){
String lv_dateFormateInUTC="";//Will hold the final converted date
Date lv_localDate = null;
String lv_localTimeZone ="";
SimpleDateFormat lv_formatter;
SimpleDateFormat lv_parser;
//create a new Date object using the timezone of the specified city
lv_parser = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
lv_parser.setTimeZone(TimeZone.getTimeZone("EST"));
try
{
lv_localDate = lv_parser.parse(p_localDateTime);
}
catch (java.text.ParseException e)
{
}
//Set output format prints "2007/10/25 18:35:07 EDT(-0400)"
lv_formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z'('Z')'");
lv_formatter.setTimeZone(TimeZone.getTimeZone(lv_localTimeZone));
System.out.println("convertLocalTimeToUTC: "p_city": "+" The Date in the local time zone " + lv_formatter.format(lv_localDate));
//Convert the date from the local timezone to UTC timezone
lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
lv_dateFormateInUTC = lv_formatter.format(lv_localDate);
System.out.println("convertLocalTimeToUTC: "p_city": "+" The Date in the UTC time zone " + lv_dateFormateInUTC);
return lv_dateFormateInUTC;
}
Hi Kiran,
Dont write import statement in UDF.
In function tab of message mapping editor add it under the standard imports.
Click on + sign and add to addtinal import.Also dont write import statement in prefix to it
Only write
java.text.SimpleDateFormat
java.util.Date.*
Also find the Updated UDF .
Here you dont need to use any sybstring or Concat
INPUT to UDF: 1994-11-05T08:15:30-05:00
OUTPUT from UDF: 1994-11-05T13:15:30Z
public String calculate(String p_localDateTime, Container container) throws StreamTransformationException{
String lv_dateFormateInUTC="";//Will hold the final converted date
Date lv_localDate = null;
String lv_localTimeZone ="";
SimpleDateFormat lv_formatter;
SimpleDateFormat lv_parser;
String date1="";
String date2="";
String date3="";
date1=p_localDateTime.substring(0,10);
date2=p_localDateTime.substring(11,19);
date3=date1+" "+date2;
//create a new Date object using the timezone of the specified city
lv_parser = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
lv_parser.setTimeZone(TimeZone.getTimeZone("EST"));
try
{
lv_localDate = lv_parser.parse(date3);
}
catch (java.text.ParseException e)
{
}
//Set output format prints "2007/10/25 18:35:07 EDT(-0400)"
lv_formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z'('Z')'");
lv_formatter.setTimeZone(TimeZone.getTimeZone(lv_localTimeZone));
//Convert the date from the local timezone to UTC timezone
lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
lv_dateFormateInUTC = lv_formatter.format(lv_localDate);
date1="";
date2="";
date3="";
date1=lv_dateFormateInUTC.substring(0,10);
date2=lv_dateFormateInUTC.substring(11,19);
date3=date1+"T"+date2+"Z";
return date3;
}Edited by: Debashish on Jul 14, 2011 9:13 AM
Edited by: Debashish on Jul 14, 2011 9:18 AM
Sorry Kiran,
use this and please let me know if it works.
Problem was because of dateformat.
String lv_dateFormateInUTC="";//Will hold the final converted date
Date lv_localDate = null;
String lv_localTimeZone ="";
SimpleDateFormat lv_formatter;
SimpleDateFormat lv_parser;
String date1="";
String date2="";
String date3="";
date1=p_localDateTime.substring(0,10);
date2=p_localDateTime.substring(11,19);
date3=date1+" "+date2;
//create a new Date object using the timezone of the specified city
lv_parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
lv_parser.setTimeZone(TimeZone.getTimeZone("EST"));
try
{
lv_localDate = lv_parser.parse(date3);
}
catch (java.text.ParseException e)
{
}
//Set output format prints "2007/10/25 18:35:07 EDT(-0400)"
lv_formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z'('Z')'");
lv_formatter.setTimeZone(TimeZone.getTimeZone(lv_localTimeZone));
//Convert the date from the local timezone to UTC timezone
lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
lv_dateFormateInUTC = lv_formatter.format(lv_localDate);
date1="";
date2="";
date3="";
date1=lv_dateFormateInUTC.substring(0,10);
date2=lv_dateFormateInUTC.substring(11,19);
date3=date1+"T"+date2+"Z";
return date3;
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.