I am developing a website that gives statistics for soccer games,and i want to convert the schedule of the match depending on the time zone. I created this function but it seems not to be working.
public static DateTime UtcToLocalTimeZone(DateTime argDateTime,TimeZoneInfo argTimeZoneInfo)
{
try
{
return TimeZoneInfo.ConvertTimeFromUtc(argDateTime, argTimeZoneInfo);
}
catch (Exception)
{
return argDateTime;
}
}
And this is how i display the date and time in my view:
TimeZoneInfo timezone = (TimeZoneInfo)Session["timeZone"] ?? TimeZoneInfo.Local;
<a style="cursor:pointer;" id="id1" versus-id="@c.MatchID" data-toggle="tooltip" data-placement="top" title="@homeMLName - @awayMLName">
@BetGuns.Web.Helper.UtcToLocalTimeZone(@c.MatchDate, timezone).ToString(dateFormat) <br />
@BetGuns.Web.Helper.UtcToLocalTimeZone(@c.MatchDate, timezone).ToString(timeFormat)
</a>