Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

I am writing a .NET application with the Stack Exchange API (using the Stacky library) and I am using it to ask the server for some questions that occured in the last hour. However, I and the server are not in the same time zone, so if I ask it for questions from DateTime.Now.AddHours(-1) to DateTime.Now, it gives me questions from 9 hours ago to 8 hours ago.

This is obviously a problem. Right now I am getting over it by asking for questions from DateTime.Now.AddHours(7) to DateTime.Now.AddHours(8), but will obviously not work for people in other time zones. How can I compensate for the time difference in such a way that it will work for all users?

share|improve this question
1  
The API uses UTC for all methods / results. You need to find a way to get the current UTC time in C#. This would make an excellent question for Stack Overflow. –  Nathan Osman May 23 '11 at 6:36
    
@George thanks, I thought questions about the API were supposed to go here. –  Seth Carnegie May 23 '11 at 6:37
1  
They are and this is certainly an on-topic question. I just thought your C# question might get a quicker answer on Stack Overflow. –  Nathan Osman May 23 '11 at 6:40
    
@George as it happens, a 2 second Google yielded DateTime.ToUniversalTime, so problem solved. If you copypaste that into an answer, I'll mark it as such. –  Seth Carnegie May 23 '11 at 6:41
    
Thanks, but you can actually add your own answer and accept it after two days - I wouldn't feel very good about posting someone else's answer. I'll gladly give you an upvote if you post it as an answer. –  Nathan Osman May 23 '11 at 16:56
add comment

1 Answer 1

up vote 4 down vote accepted

As I learned from George Edison in his comment, the server handles time in UTC format. Just replace your calls to DateTime.Now with DateTime.UtcNow or you can convert any DateTime to UTC format with the ToUniversalTime method. Just make sure not to call ToUniversalTime on the server's time, or it'll get messed up.

share|improve this answer
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .