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

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);
Sign up to request clarification or add additional context in comments.

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.