0

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>
5
Contributors
7
Replies
47
Views
6 Days
Discussion Span
Last Post by JamesCherrill
2

Not to be working...
WHAT is not working?
Error codes, your program blew up etc.
Tell us.

0

Thank you it was helpfult that article,but i think that i have a problem with how i take user timezone:
TimeZoneInfo timezone = (TimeZoneInfo)Session["timeZone"] ?? TimeZoneInfo.Local;

0

After having written a LOT of time conversion software over the years I can only say this. DO NOT GUESS! Study the domain and understand what is required to convert from one timezone to another. My software had to work properly in countries all over the world (China, Japan, Korea, India, Europe, USA, et al). I'm not going to try to teach you how to do this, but is isn't that hard if you make some effort!

0

having written a LOT of time conversion software over the years

Why? There's proven tested supported code out there that does it. Do you have some kind of magic time-lord insight that means they are all wrong and only you can get it right?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.