TalendDate.getCurrentDate() in GMT

One Star

TalendDate.getCurrentDate() in GMT

Hi
I am trying to update a date field using TalendDate.getCurrentDate() function in tMap but this one updates the field with local time zone. Is there a way to update the field in GMT?
Thanks
Kalyan
Seventeen Stars

Re: TalendDate.getCurrentDate() in GMT

The java Date object has non timezone. It is always UTC based. The timezone is actually only relevant if you want to render a date.
If you have a Date and you need to move it into GMT you have to know the necessary bias.
Use the function TalendDate.addDate:

TalendDate.addDate(TalendDate.getCurrentDate(), -1,"HH")

This example moves the current date one hour in the past.
One Star

Re: TalendDate.getCurrentDate() in GMT

Hi kalyan,
Try this expression TalendDate.parseDate("dd MMM yyyy HH:mm:ss",TalendDate.getCurrentDate().toGMTString()) 
and let me know it's working for you or not.
Seventeen Stars

Re: TalendDate.getCurrentDate() in GMT

I am not sure if the toGMTString method always returns the same format and it actually does not solve the problem because the parser depends also from the local timezone of the job server. I would not recommend that!
By far better is if you know which is the original timezone of the given date and move it with the correct bias.
One Star

Re: TalendDate.getCurrentDate() in GMT

Time zone varies between environments. I cannot write code specific to environments.
One Star

Re: TalendDate.getCurrentDate() in GMT

I tried the option of TalendDate.parseDate("dd MMM yyyy HH:mm:ss",TalendDate.getCurrentDate().toGMTString())

This works fine on output object if the action on data is set to Insert. But the same thing fails to load the date time in GMT if the action on data is set to Insert or update.
Any ideas?
One Star

Re: TalendDate.getCurrentDate() in GMT

can you please provide error on Insert or update action and also provide 1 sample date which you are trying to update.
Seventeen Stars

Re: TalendDate.getCurrentDate() in GMT

Ok guys, it works fine? This method is deprecated! Oracle can remove this without any notification in the next Java release.
This is a quick and dirty solution and by far not professional.
One Star

Re: TalendDate.getCurrentDate() in GMT

Hi
Attached screenshot#1 has my job.
There are 2 if conditions.
Action on data is set to Insert only on final output (S_BU) object with If Condition 1.
Action on data is set to Insert or Update on final output (S_BU) object with If Condition 2.
If Condition 1 is true then date is getting stored correctly in GMT. But if 2nd condition is true then the 2 fields are getting stored in my local date time.
Why is such an odd behavior?
Thanks
Kalyan