In my WPF .NET client application I assign a DateTime
variable the current Time value:
class MyClass
{
public DateTime CreatedDate {get; set;}
}
MyClass myClass = new MyClass();
myClass.CreatedDate = DateTime.Now;
After the assignment I send the object to a WCF service located in Europe (UTC+1) that saves the object in the database. If client and service are in the same TimeZone
there are no issues. However if I change TimeZone
, for instance my client is in (UTC-6) and service in (UCT+1), the service will read the CreatedDate value as it is DateTime.Now on the service so (UCT+1) instead of (UCT-6) as assigned on the client. If set CreatedDate on the client (UTC-6) the 31/10/2014 at 20:00 in the service it will be stored as (UTC+1) the 01/11/2014 at 01:00 and this affects some processes on my system.
This is not the behavior that I would like to have, I want the service always to store that Date as submitted by the client.
I have access to the code for both server and client, I tried to set when assign the CreatedDate
as:
myClass.CreatedDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified);
with no luck. The only solution I can think about is to use string instead of DateTime but that implies a lot of changes in the code. Anybody know a way to ignorne the TimeZone
settings?