AnsweredAssumed Answered

Date conversion from any timezone without daylight savings issue

Question asked by nunnapradeep868228 on Jun 25, 2017
Latest reply on Jun 26, 2017 by Sjaak Overgaauw

Hi All,

 

I have prepared this simple Groovy script, which we can use in any map. This will help to convert any datetime from one timezone to other/UTC without any daylight savings issue.

 

 

#Timezone 

 

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.*;

 

ZoneId sourceZone = ZoneId.of("Australia/Sydney");
String sourceDate = indate;

 

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

LocalDateTime localtDateAndTime = LocalDateTime.parse(sourceDate, formatter);


ZonedDateTime dateAndTimeInSource = ZonedDateTime.of(localtDateAndTime, sourceZone );

ZonedDateTime utcTargetDate = dateAndTimeInSource.withZoneSameInstant(ZoneOffset.UTC);

 

opdate = utcTargetDate;

 

 

Regards,

Pradeep

Outcomes