开发者

Invariant dates with WCF RIA Services

开发者 https://www.devze.com 2023-01-12 14:49 出处:网络
Is there any way to prevent Silverlight/RIA Services from converting a datetime object on the wire? Right now, I see datetimes set to \'Local\' or \'Unspecified\' being converted to the local time of

Is there any way to prevent Silverlight/RIA Services from converting a datetime object on the wire?

Right now, I see datetimes set to 'Local' or 'Unspecified' being converted to the local time of the server when they are sent over the wire.

For 开发者_JAVA百科example:

The client and server are both in UTC -04:00:00.

  • I use DateTime.Today (kind is either Local or Unspecified, it doesn't make a difference) on the Silverlight client. I see 23/08/2010 00:00:00.
  • I submit my changes and watch the data go over the wire. The field is expressed at 23/08/2010 00:00:00 (-04:00:00).

Great. Now I change my client to be in UTC +12:00:00

  • I use DateTime.Today on the client and now I see 24/08/2010 00:00:00.
  • HOWEVER - I submit my changes and watch the data again. Now I see 23/08/2010 08:00:00 (-04:00:00).

So it is apparent that the serializer is converting to the local time of the server, which I do not want. The value I want in the DB is 24/08/2010 00:00:00.

Using UTC is not a great option for this field as the database is part of our legacy application and the column contains invariant dates at this time. I don't want to start inserting UTC datetimes alongside the existing data.

Any ideas?

Thanks in advance


If I create the DateTime like this, it works:

new DateTime(DateTime.Now.Ticks, DateTimeKind.Unspecified).Date;
0

精彩评论

暂无评论...
验证码 换一张
取 消