Elapsed Time and timezones question

jake

Member
Licensed User
Longtime User
If I capture datetime.now as startTime, allow some time to pass, then use datetime.now as endTime their difference gives an accurate elapsed time.

But I'm wondering about the scenario where the phone is traveling, and the startTime occurs in one timezone, but endTime occurs in an adjacent timezone. if I use the difference between startTime and endTime (as described above), could I have a potential inaccuracy due to timezone?

Looking at some other threads I saw the line of code below(from Klaus):

dt = DateTime.DateParse(DateTime.Date(DateTime.Now))

If I use:

lngStartTime=DateTime.DateParse(DateTime.Date(DateTime.Now))
lngEndTime=DateTime.DateParse(DateTime.Date(DateTime.Now))

with lngEndTime in a different timezone from lngStartTime, would the difference between these two always give me a correct elapsed time regardless of timezone?
 

jake

Member
Licensed User
Longtime User
I was just imagining that out here in the Western U.S. If I was in the Mountain timezone just East of the time line, and did datetime.now, then traveled West across the line into the Mountain timezone and did datetime.now again, that I might end up with a negative elapsed time.

Is there any scenario where datetime.now once I change timezones could update to the new timezone and lead to a negative elapsed time?

I'm still a little confused on this issue because I would expect the phones clock to update when I cross a time line. Wouldn't this mean datetime.now would update also?
 
Upvote 0

jake

Member
Licensed User
Longtime User
I understand now. Datetime.now is relative to UTC so timezone isn't an issue!

Thanks Erel.
 
Upvote 0
Top