19
Views
2
Comments
[Geo] Error when invoking Timezone_ConvertTimezoneByCode
Question
geo
Web icon
Forge asset by Geo Team
When invoking this action Timezone_ConvertTimezoneByCode, encountered below error:
The time zone ID 'Etc/GMT' was not found on the local computer.

Anyone faced this and what is the problem?

2018-03-08 20-43-12
Robert Chanphakeo
Hello Lian

This error occurs because the server where you installed GEO component does not have ETC/GMT win32 timezone, a better solution would be to modify the internal GEO Timezone_ConvertTimezoneByCode method to use Nodatime class library https://nodatime.org/ 
2018-03-08 20-43-12
Robert Chanphakeo
Lian

Try the code below, let me know if you have any issues.

/// <summary>
/// Convert UTC DateTime into another timezone.
/// </summary>
/// <param name="ssUTCDateTime"></param>
/// <param name="ssToTimezoneCode"></param>
/// <param name="ssToDateTime"></param>
public void MssGeo_ConvertUTCTimezone(DateTime ssUTCDateTime, string ssToTimezoneCode, out DateTime ssToDateTime)
{
ssToDateTime = new DateTime(1900, 1, 1, 0, 0, 0);

DateTime utcDateTime = TimeZoneInfo.ConvertTimeToUtc(ssUTCDateTime);
var resultTimeZoneId = DateTimeZoneProviders.Tzdb[ssToTimezoneCode];  
DateTime resultDateTime = Instant.FromDateTimeUtc(utcDateTime).InZone(resultTimeZoneId).ToDateTimeUnspecified();

ssToDateTime = resultDateTime;

} // MssGeo_ConvertUTCTimezone

Note: I havent tested it.

 
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.