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: 
aambasht1626789554
Contributor
Contributor

Convert UTC date to US Central Time

I am reading data from Salesforce objects. It has a date field in UTC format as shown below. How do i convert this date into US Central Time when loading into a file?

0695b00000H7pkvAAB.png

Labels (3)
5 Replies
gjeremy1617088143

Hi,

maybe TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss z yyyy", String.valueOf(input_row.newColumn),"en-US");

Send me Love and kudos

aambasht1626789554
Contributor
Contributor
Author

Thanks! It appears that it doesn't convert to central time. Please see below, the left field is the input date in UTC and the right field is the converted date using the above code.

 0695b00000H7qkXAAR.png

gjeremy1617088143

Maybe you can refer to this topic :

https://community.talend.com/s/feed/0D73p000004kZwJCAU?language=en_US

@Fred Trebuchet​ made a custom routine to convert utc to local time.

 

gjeremy1617088143

so you can write this routine :

 

 

package routines;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

 

 

public class TimeConvert {

 

public static Date convertTzToTz(String strDate, String inTz, String outTz) throws Exception

{

if (strDate == null || inTz == null || outTz == null)

return null;

 

// Convert strDate from any valid timezone such Europe/Paris to another one

// strDate is expected to be formatted as "yyyy-MM-ddTHH:mm:ssZ"

 

SimpleDateFormat indfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

indfm.setTimeZone(TimeZone.getTimeZone(inTz));

Date inDate = indfm.parse(strDate);

 

SimpleDateFormat outdfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

outdfm.setTimeZone(TimeZone.getTimeZone(outTz));

 

return TalendDate.parseDate("yyyy-MM-dd'T'HH:mm:ssZ",outdfm.format(inDate));

}

}

 

and call it in your job :

TimeConvert.convertTzToTz((your input column),"UTC","US/Central");

 

your input date have to be in string format and the output will be a date with the pattern you want in the output schema of the component :

if your input is in date format :

TimeConvert.convertTzToTz(TalendDate.formatDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",(your input)),"UTC","US/Central");

 

here is the result :

input :

2021-07-15T17:54:39.000Z

2021-07-15T17:54:48.000Z

 

output:

15-07-2021 12:54:39

15-07-2021 12:54:48

 

gjeremy1617088143

Hi @anshumali ambasht​ , did you solve your issue ?

If one of my answer help you to achieve it, please select it as best answer.

Send me love and kudos