Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Date are covnerted to UTC dates automatically RSS

11 replies

Last post Apr 29, 2009 10:46 AM by rid00z

(0)
  • ccchai

    ccchai

    Member

    194 Points

    76 Posts

    Date are covnerted to UTC dates automatically

    Apr 07, 2009 10:40 AM | LINK

     The dates are automatically converted into UTC dates at client side when I do querying. Is there a way to turn off this behaviour?

     

  • WilcoB

    WilcoB

    Participant

    786 Points

    146 Posts

    Re: Date are covnerted to UTC dates automatically

    Apr 07, 2009 08:00 PM | LINK

    You can override UseUtcDateTimes in your DomainService and return false.

    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • ccchai

    ccchai

    Member

    194 Points

    76 Posts

    Re: Date are covnerted to UTC dates automatically

    Apr 08, 2009 08:07 AM | LINK

     Actually, the UseUtcDateTimes is already return false, but somehow the dates still get converted to UTC dates at client side.

  • WilcoB

    WilcoB

    Participant

    786 Points

    146 Posts

    Re: Date are covnerted to UTC dates automatically

    Apr 08, 2009 08:11 PM | LINK

    What kind of DateTimes are you returning from the server (check DateTime.Kind)? Unspecified, Local or Utc? Unless they're local, I believe the serializer will assume the dates are UTC.

    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • mathewc

    mathewc

    Participant

    1030 Points

    184 Posts

    Microsoft

    Re: Date are covnerted to UTC dates automatically

    Apr 09, 2009 12:47 AM | LINK

    As Wilco said, the client DataContractJsonSerializer and server JavaScriptJsonSerializers we're using send UTC over the wire. Therefore, you'll always recieve UTC on the client, and if you want to display Local times, you'll have to do that conversion yourself - our client components do no conversions.

    Details on DomainService.UsesUtcDateTimes: Our LinqToEntities and LinqToSql domain services override the base implementation (which returns true), both returning false, since that is the behavior we deemed most common. This means that the LTS/LTE domain services are doing conversions to Local time. You can override this property and return true if you're storing UTC times in your DB and you don't want any conversions. If you override and set UsesUtcDateTimes = true, our serializer won't perform any conversions to the time read from the datasource.

    -Mathew [MSFT]
  • ccchai

    ccchai

    Member

    194 Points

    76 Posts

    Re: Date are covnerted to UTC dates automatically

    Apr 09, 2009 04:29 AM | LINK

    Changing DateTime.Kind value at server and client side does not have any effect.

    And also, changing UsesUtcDateTimes at domain service to true / false has no effect, too.

    The solution I am using now is to add back the missing hours using IValueConverter.

  • mathewc

    mathewc

    Participant

    1030 Points

    184 Posts

    Microsoft

    Re: Date are covnerted to UTC dates automatically

    Apr 09, 2009 05:24 PM | LINK

    I assume on the client you're using the correct DateTime.ToLocal/ToUniversalTime methods for the conversions? If you're storing Local times in your datasoruce, they will be converted to UTC on the wire but doing a ToLocal on them client side should get you your original local time.

    -Mathew [MSFT]
  • callmeknud

    callmeknud

    Member

    16 Points

    84 Posts

    Re: Date are covnerted to UTC dates automatically

    Apr 17, 2009 01:03 PM | LINK

    i have the same problem, could somebody please tell me where i can set UsesUtcDateTimes = true so that no conversion will be done?

    thanks!

  • ccchai

    ccchai

    Member

    194 Points

    76 Posts

    Re: Date are covnerted to UTC dates automatically

    Apr 17, 2009 01:32 PM | LINK

     UsesUtcDateTimes is a overridable readonly-property in DomainService class. You can override it and return true. But as I mentioned in earlier posting, it does not work. It is the problem of JSON serialization itself. So, I have to use IValueConverter at client side.

  • callmeknud

    callmeknud

    Member

    16 Points

    84 Posts

    Re: Date are covnerted to UTC dates automatically

    Apr 17, 2009 01:51 PM | LINK

    thanks for your reply!

    So you don't use DateTime.ToLocal or something like that, instead you add the hours directly to the DateTime Values?

    Thank you!