none
DateTime.Now diferent Timezones RRS feed

  • Question

  • Hello guys,

       I got a huge problem. I started developing a wpf web app with a remote wpf desktop app that manages some wcf services and stuff.

       The web app is to be used by different clients all over the world with different timeZones, and the problem is that i'm using the datetime.now, but... the client could have the time wrong on the computer and it messes the data... 

    I thought in a wcf service in the administration app that would return the correct datetime for each client regarding his timezone. Is it a good approach?

    Wednesday, June 12, 2013 6:20 PM

Answers

  • That's a very good point! But, What if... the time in the client computer is wrong?
    If you're doing everything with UtcNow, it shouldn't matter much.  You can always compute the time stamps you use on the server, not the client....

    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Jorge_M_P Friday, June 14, 2013 11:32 AM
    Thursday, June 13, 2013 4:21 PM

All replies

  • You should design your system to work with times in UTC.  You can then have the clients convert to their local time for display.

    Basically, just use DateTime.UtcNow instead of DateTime.Now everywhere, and convert from UTC to Local time as needed via ToLocalTime .


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, June 12, 2013 6:29 PM
  • That's a very good point! But, What if... the time in the client computer is wrong?
    Thursday, June 13, 2013 8:10 AM
  • That's a very good point! But, What if... the time in the client computer is wrong?
    If you're doing everything with UtcNow, it shouldn't matter much.  You can always compute the time stamps you use on the server, not the client....

    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Jorge_M_P Friday, June 14, 2013 11:32 AM
    Thursday, June 13, 2013 4:21 PM