I had the interesting request that it was important to a system (SalesForce) to set the right time including the timezone.

So I created a .Net function with a string as input and a string as output. This function is call from a map. Here are the function:

DateTime myDateTime = Convert.ToDateTime(input);
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(“W. Europe
Standard Time”
);
TimeSpan offset =
tzi.GetUtcOffset(myDateTime);
DateTimeOffset d = new DateTimeOffset(myDateTime, offset);
string
output = d.ToString(
“o”);

The Id of the zone can be found by running through all the names by running this code:

ReadOnlyCollection<TimeZoneInfo> zones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine("The local system has the following {0} time zones", zones.Count);
foreach (TimeZoneInfo zone in zones)
   Console.WriteLine(zone.Id);
The result is in a format that this, which also takes care of DST (Daylight saving time):
2012-07-02T02:12:00.0000000+02:00 (input --> 02-07-2012 02:12) 2012-02-28T14:00:00.0000000+01:00 (input --> 28-02-2012 14:00)

Random posts:

Help me, help you. You know how 😉 (click, click, click…)