Getting time for a particular time zone RRS feed

  • Question

  • User-2097295820 posted

    I just built my web application. which is hosted on a european server in azure. Unfortunately my users a basically in Nigeria for now.

    So I notice that when testing time is sometimes an issue. some times latest ness in 1 hour.

    I would paste my time script. I need a time that would always tally with Nigerian time.

     public TimeSpan CurrentTime(){
                  DateTime today = DateTime.Now;
                    TimeSpan currentTime = TimeSpan.Parse(DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss"));
                    return currentTime;

    That is the current script I am using. I read on line that I should use Timezone.

    please give me suggestions

    Friday, December 9, 2016 12:56 PM

All replies

  • User-691209617 posted

    For this you can use TimeZoneInfo for more details see this link

       TimeZoneInfo hwZone = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time");
       Console.WriteLine("{0} {1} is {2} local time.", 
               hwZone.IsDaylightSavingTime(hwTime) ? hwZone.DaylightName : hwZone.StandardName, 
               TimeZoneInfo.ConvertTime(hwTime, hwZone, TimeZoneInfo.Local));
    catch (TimeZoneNotFoundException)
       Console.WriteLine("The registry does not define the Hawaiian Standard Time zone.");
    catch (InvalidTimeZoneException)
       Console.WriteLine("Registry data on the Hawaiian STandard Time zone has been corrupted.");

    Friday, December 9, 2016 1:07 PM
  • User-2097295820 posted

    From what I can see timezone somethings are not found on some server computers. Is there a way for me to check the Timezone that Azure supports. My app is hosted on windows azure. Thanks alot. As much as I need to implement this solution in my project fast. I am scared of getting exceptions of Timezone notfound. Because this would break my app flow.

    Dont worry I would mark you answer if it satisfy me.

    Thanks alot.

    Saturday, December 10, 2016 9:05 AM
  • User1564875471 posted

    I would paste my time script. I need a time that would always tally with Nigerian time.


    Windows Azure makes it easy for you to specify the time zone your site will be using by setting a specific application setting named "WEBSITE_TIME_ZONE" , refer here

    Saturday, December 10, 2016 10:54 AM