Seven Stars

String to Date Conversion in Talend

How to Convert this "Tue, 26 Jun 2018 09:00:15 -0500" {Datatype - String} into "20180626" {Datatype - String
and another is 

How to Convert this "Wed Jun 27 15:57:11 IST 2018" {Datatype - String} into "20180626" {Datatype - String

 

 

By Using TalendDate.parseDate it throws Unparsable Date error  !!

1 ACCEPTED SOLUTION

Accepted Solutions
Nine Stars

Re: String to Date Conversion in Talend

Sorry, copy pasted wrong code.

System.out.println(TalendDate.parseDate("EEE, dd MMM yyyy HH:mm:ss Z","Thu, 21 Jun 2018 12:22:00 -0500"));

System.out.println(TalendDate.parseDate("EEE MMM dd HH:mm:ss Z yyyy","Wed Jun 27 15:57:11 IST 2018"));
4 REPLIES
Nine Stars

Re: String to Date Conversion in Talend

"Tue, 26 Jun 2018 09:00:15 -0500" use this format : "E, dd MMM yyyy HH:mm:ss XXX"
"Wed Jun 27 15:57:11 IST 2018" use this format : "E MMM dd HH:mm:ss Z yyyy"
Seven Stars

Re: String to Date Conversion in Talend

@Dijke

 

I'm getting this error

Exception in component tFileCopy_6 (FetchFromGmail)
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "Thu, 21 Jun 2018 09:00:31 -0500"
at routines.TalendDate.parseDate(TalendDate.java:898)
at routines.TalendDate.parseDate(TalendDate.java:842)
at delwarejob.fetchfromgmail_0_1.FetchFromGmail.tPOP_5Process(FetchFromGmail.java:1506)
at delwarejob.fetchfromgmail_0_1.FetchFromGmail.runJobInTOS(FetchFromGmail.java:2185)
at delwarejob.fetchfromgmail_0_1.FetchFromGmail.main(FetchFromGmail.java:1807)
Caused by: java.text.ParseException: Unparseable date: "Thu, 21 Jun 2018 09:00:31 -0500"
at java.text.DateFormat.parse(Unknown Source)
at routines.TalendDate.parseDate(TalendDate.java:884)
... 4 more

Nine Stars

Re: String to Date Conversion in Talend

Sorry, copy pasted wrong code.

System.out.println(TalendDate.parseDate("EEE, dd MMM yyyy HH:mm:ss Z","Thu, 21 Jun 2018 12:22:00 -0500"));

System.out.println(TalendDate.parseDate("EEE MMM dd HH:mm:ss Z yyyy","Wed Jun 27 15:57:11 IST 2018"));
Seven Stars

Re: String to Date Conversion in Talend

Thanks @Dijke

[Solved]

Works very fine to me