Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
RA6
Creator

DateTime Europe/Paris zone Conversion

Hello guys,

I have an input as timestamp in the following format:

 

timestamp

2022-03-27T16:09:41.077296+00:00

 

I need to convert it to france time which take care of summer/winter time also. Normally, for this conversion, i have created a routine and it works well but i cannot deploy the job because the java class i am using is in a newer version rather than the deployment server.

 

Development Server : java version "1.8.0_281"

Deployment Server : Java version "1.7.0_79"

 

Expected Result:

 

Input | Expected Result | Comment

2022-03-24T16:09:41.077296+00:00 | 2022-03-24T17:09:41.077296+01:00 | Winter time

2022-03-27T16:09:41.077296+00:00 | 2022-03-27T18:09:41.077296+02:00 | Summer time

 

package routines;

 

import java.time.format.DateTimeFormatter;

import java.time.ZonedDateTime; =>use java 1.8

import java.time.ZoneId; =>use java 1.8

 

public class ConvertParisUTC {

  public static String dateTimeParis(String date)

  ZoneId paris = ZoneId.of("Europe/Paris");

    DateTimeFormatter isoFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

    ZonedDateTime date1 = ZonedDateTime.parse(date, isoFormatter).withZoneSameInstant(paris);

    return (date1.format(isoFormatter));

  }

}

 

 

Questions:

Is there another routine that can be used to do this conversion?

Is there a possible way to get the expected result without a routine?

 

Best regards,

RA

Labels (3)
1 Solution

Accepted Solutions
gjeremy1617088143

Hi @Rohit Aftab​ , for java 7 you could try something like this :

 

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.TimeZone;

 

public class DateFormatter {

 

/**

* Utility function to convert java Date to TimeZone format

* @param date

* @param format

* @param timeZone

* @return

*/

public static String formatDateToString(Date date, String format,

String timeZone) {

// null check

if (date == null) return null;

// create SimpleDateFormat object with input format

SimpleDateFormat sdf = new SimpleDateFormat(format);

// default system timezone if passed null or empty

if (timeZone == null || "".equalsIgnoreCase(timeZone.trim())) {

timeZone = Calendar.getInstance().getTimeZone().getID();

}

// set timezone to SimpleDateFormat

sdf.setTimeZone(TimeZone.getTimeZone(timeZone));

// return Date in required format with timezone as String

return sdf.format(date);

}

View solution in original post

3 Replies
Anonymous
Not applicable

Hi

Have you read this post, TRF shared a routine.

 

Regards

Shong

gjeremy1617088143

Hi @Rohit Aftab​ , for java 7 you could try something like this :

 

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.TimeZone;

 

public class DateFormatter {

 

/**

* Utility function to convert java Date to TimeZone format

* @param date

* @param format

* @param timeZone

* @return

*/

public static String formatDateToString(Date date, String format,

String timeZone) {

// null check

if (date == null) return null;

// create SimpleDateFormat object with input format

SimpleDateFormat sdf = new SimpleDateFormat(format);

// default system timezone if passed null or empty

if (timeZone == null || "".equalsIgnoreCase(timeZone.trim())) {

timeZone = Calendar.getInstance().getTimeZone().getID();

}

// set timezone to SimpleDateFormat

sdf.setTimeZone(TimeZone.getTimeZone(timeZone));

// return Date in required format with timezone as String

return sdf.format(date);

}

RA6
Creator
Author

@Shicong Hong​ 

@guenneguez jeremy​ 

 

I have tested it with the following function and it works.

I haven't mention any timezone but am achieving the expected result.

 

TalendDate.parseDateInUTC

 

 

Input | Expected Result | Comment

2022-03-24T16:09:41.077296+00:00 2022-03-24T17:09:41.077296+01:00 Winter time

2022-03-27T16:09:41.077296+00:00 2022-03-27T18:09:41.077296+02:00 Summer time

 

 

Best regards,

RA