Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Edith1
Creator
Creator

tMap Expression Function to convert UTC to local time

Hello, thanks in advance for reading and helping me out with the following question.

In Data Catalog, there's an attribute of "last modified date" and it shows both the Local Time and UTC Time. When I pull this data using the Data Catalog API, I'm only getting the UTC time. Is there a function or expression in tMap to convert the UTC to local? In the below picture, the API pulls 2020-10-05 22:26:32. Is there a way to convert this to 15:26:32? I was looking at the Talend Date functions, but not sure how to use them. Would tformatDateLocale() work?

0693p000009rjZDAAY.jpg

Here's a picture of my job.

0693p000009rjvBAAQ.jpg

5 Replies
DataTeam1
Creator
Creator

@Edith Murillo​ I think you can use this function: TalendDate.addDate(yourUTC_Date, -7, "HH") to get 7 hours earlier time then yourUTC_Date.

Edith1
Creator
Creator
Author

Thanks for the reply. I did get this to work, however, as I was testing the date against the application I came across dates that are difference of -8 instead of -7. The daylight savings is -7, but how do I incorporate when we're not in daylight savings? How do I code, IF DAYLIGHT SAVINGS then TalendDate.addDate(yourUTC_Date, -7, "HH") else TalendDate.addDate(yourUTC_Date, -8, "HH") ?

cadap
Contributor III
Contributor III

Hi,

 

that's the reason why the Timezones exist.

 

Personally I use the "new" Java DateTime classes LocalDate and LocalDateTime, which of course can be converted to a Java "Date" (which Talend uses), because it is much simpler to work with.

 

For instance:

 

ZoneId zoneId = ZoneId.of("UTC") or ZoneId zoneId = ZoneId.of("Europe/Berlin")

 

gives you the ZoneId of the corresponding TimeZone and "knows" about the daylight saving time.

 

If you take the TimeZones into the date to string conversion, you will get the correct time for this timezone.

 

Exampe:

LocalDateTime localDateTime = LocalDateTime.now(zoneId); //actual time in the defined timeZone

 

You can of course convert ever date or datetime with a zoneId.

 

br

Edith1
Creator
Creator
Author

Is there a function in tMap to convert the UTC into the local time?

If I format the date as "Z" in tMap, then I get the -0800 or -0700 (timeZone column below)

If I format the date "yyyy-MM-dd HH:mm:ss.SSSXXX", then I get the date and the time zone (convertedDate column)

 

Is there a way to use this? Subtract the timeZone from the originalDate to get the local time?

 

0693p000009ryz3AAA.jpg

 

Edith1
Creator
Creator
Author

There's a solution to do this with tMap date functions!

 

TalendDate.parseDateInUTC("yyyy-MM-dd HH:mm:ss", row1.Value )

 

The above expression is converting the originalDate to the newColumn, which is correct according to the time zone.

 

0693p000009s0czAAA.jpg