-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DateTimeOffset Formatting is not working #3008
Comments
It is working as intended. You just need to pay utmost attention to the details here. EDIT: To future readers, The example code you linked to is a red herring. Note how the example code uses To understand, pay attention to the Note how the default value for this setting use the
(Also see the table with So, basically, as per the (Disclaimer: I am not author/maintainer of this library. I am just a fellow, mostly former user of this library.) |
Thanks for your reply. |
No. The first "help" link correctly says it applies to You gotta really pay attention. The |
I'm sorry. |
"+00:00" is UTC base time. So why exactly would you believe that EDIT: To future readers, |
my english is not very good, so i'll try to explain I was expecting, the result string be formatted as UTC. |
If it is important to you to stringify/serialize UTC With respect to Newtonsoft.Json, you have to do this in the WriteJson method of a custom JsonConverter which you will have to write. If you also need to deserialize json date/time strings with a "Z" suffix into (Why the creators of the .NET Framework many, many years ago decided to string-format UTC time zone for |
I appreciate your time and patience. You are the best. |
Oh, one major correction. You were right regarding the documentation at https://www.newtonsoft.com/json/help/html/SerializeDateTimeZoneHandling.htm being not correct.
Using |
I tried to use the setting described here https://www.newtonsoft.com/json/help/html/SerializeDateTimeZoneHandling.htm
but it does't work :(
var jSetting = new JsonSerializerSettings();
jSetting.ContractResolver = new CamelCasePropertyNamesContractResolver();
jSetting.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
var jsonObj = JsonConvert.SerializeObject(objList, jSetting);
in the result all datetime include the offset "+00:00"
The text was updated successfully, but these errors were encountered: