Generally speaking, the REST and SOAP APIs transfer DateTime values in the UTC Timezone. From Primitive Data Types - DateTime (my emphasis)
Date/time values (timestamps). Fields of this type handle date/time values (timestamps), such as ActivityDateTime in the Event object or the CreatedDate, LastModifiedDate, or SystemModstamp in many objects. Regular dateTime fields are full timestamps with a precision of one second. They are always transferred in the Coordinated Universal Time (UTC) time zone. In your client application, you might need to translate the timestamp to or from a local time zone.
Internally the Force.com Toolkit is using Json.NET to parse the response from the REST API. This occurs in HttpGetAsync<T>
.
I found in the question How to preserve timezone when deserializing DateTime using JSON.NET? that if you changed your object property from DateTime
to DateTimeOffset
you could get the correct underlying UTC value.
E.g.
private class Lead
{
public const string SObjectTypeName = "Lead";
public string Id { get; set; }
public DateTimeOffset CreatedDate { get; set; }
}
Then when you query it you can get the underlying UTC value:
//...
Console.WriteLine("Connected to Salesforce");
var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
QueryResult<Lead> leads = await client.QueryAsync<Lead>("Select Id, CreatedDate from Lead limit 10");
foreach(Lead l in leads.Records)
{
Console.Out.WriteLine("ID:{0} CreatedDate:{1} ISO 8601:{2}", l.Id, l.CreatedDate,
l.CreatedDate.UtcDateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", System.Globalization.CultureInfo.InvariantCulture));
}
