convertToCurrentTimeZone static method
Implementation
static DateTime convertToCurrentTimeZone(
DateTime dateTime, String fromTimeZone, String toTimeZone) {
// Parse the input datetime with the source timezone
DateTime parsedDateTime = DateFormat('yyyy-MM-dd HH:mm:ss')
.parse(dateTime.toString(), true)
.toLocal();
// Convert the datetime to the target timezone
DateTime convertedDateTime = parsedDateTime.toUtc().add(Duration(
hours:
getTimeZoneOffset(toTimeZone) - getTimeZoneOffset(fromTimeZone)));
return convertedDateTime;
}