0

My application consumes the APIs, one of the API returns the Datetime value with unix time format

ex: user.DateOfBirth = "/Date(476197200000+1100)/" 

The deserialize process is working well (deserialize<User> object) but when I display the datetime to GUI.

the UI displays this date as 2/Feb/1985 My expected is: 3/Feb/1985

My local environment displays correctly, it's 3/Feb/1985, but on UAT environment, it display less than 1 day (2/Feb/1985)

I'm using Newtonsoft.Json v10.x.x

James Z
12.3k10 gold badges27 silver badges48 bronze badges
asked Nov 24, 2018 at 4:42

1 Answer 1

1

Not sure how you are deserializing but you might want to look into how to parse using specific time zone.

You can try this.

microsoftDateFormatSettings = 
new { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
 DateTimeZoneHandling = DateTimeZoneHandling.Local};
var items = JsonConvert.DeserializeObject<List<lstObject>>.
(jsonString, microsoftDateFormatSettings);
answered Nov 24, 2018 at 4:54

4 Comments

Hello Rushikesh Vyas Thanks for your reply, yes, I have been serializing as your above suggestion, I also add ateTimeZoneHandling.Local but not success My Json is: "DateOfBirth":"\/Date(784731600000+1100)\/" My Customer has: [Description("The contacts date of birth.")] [DataMember(IsRequired = false)] public DateTime? DateOfBirth { get; set; } Could you help me in this case? Thank you
Can you show the snippet of your code?that’d be a great help.
It's exactly the same like you, the difference is using <T> object instead of List<object>, and microsoftDateFormatSettings change to your suggestion above Thank you
So do you see the correct value when you deserialize and UI control is showing wrong date? Or when you deserialize json you are getting incorrect information

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.