none
Question about the DateTime.Ticks RRS feed

  • Question

  • Hi there

    Does DateTime.Ticks depend on end-user time zone?

    The problem is that if I issue a validation ticket for the client and make the part of the ticket a server's Ticks, could it be that the ticket is found expired cause the client's computer time has huge offset due to time zone (or set up incorrectly)?

    Do all computers in the world provide the same Ticks for given moment of time in spite of location?

    Both server and client code is based on .NET

    Thanks.

    Wednesday, June 25, 2014 4:55 PM

Answers

  • Ticks does not take into account time zone, so you would have a problem as you describe, if you use DateTime.Now.Ticks.

    However, the solution is simple, always use DateTime.UtcNow.Ticks, and time zones are effective factored out.

    Regards,

    Nick

    • Marked as answer by Renziglov Friday, June 27, 2014 2:31 PM
    Thursday, June 26, 2014 8:42 PM

All replies

  • Hello,

    >>Does DateTime.Ticks depend on end-user time zone?

    No, it is described clearly:

    The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001, which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.

    It starts from 12:00:00 midnight, January 1, 0001.

    However, if you use the DateTime.Now.Ticks, it depends on end-user time zone.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 26, 2014 4:21 AM
    Moderator
  • Fred

    Your answer is

    >No, it is described clearly

    >However, if you use the DateTime.Now.Ticks, it depends on end-user time zone That means Yes

    So Yes or No?

    Ok, let me re-phrase it. If I issue a token, based on Ticks, with 1 min expiry time in, let's say, Otawa and send it to the client in Barcelona, that client will always gets it expired regardless the sending itself actually tooks a couple of microseconds? And the reasion will be the fact that the Barcelona's time zone has 4 hours lag which apparently more than 1 min?

    Is that the case?

    Thanks.

    Thursday, June 26, 2014 5:12 PM
  • Ticks does not take into account time zone, so you would have a problem as you describe, if you use DateTime.Now.Ticks.

    However, the solution is simple, always use DateTime.UtcNow.Ticks, and time zones are effective factored out.

    Regards,

    Nick

    • Marked as answer by Renziglov Friday, June 27, 2014 2:31 PM
    Thursday, June 26, 2014 8:42 PM
  • I've never paid attention to DateTime.UtcNow.

    Very usefull, thanks

    Friday, June 27, 2014 2:31 PM