Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7923239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:14:50+00:00 2026-06-03T17:14:50+00:00

I have a Nancy JSON REST service that uses the following serialisation code… FormatterExtensions.AsJson(this.Response,

  • 0

I have a Nancy JSON REST service that uses the following serialisation code…

FormatterExtensions.AsJson(this.Response, insightManager.CaseSummary(x.caseId));

Which is then deserilised by…

    public static T ParseResponseForObject<T>(string response)
    {
        var javaScriptSerializer = new JavaScriptSerializer();
        try
        {
            return javaScriptSerializer.Deserialize<T>(response);
        }
        catch (Exception ex)
        {
            throw new Exception(response, ex);
        }
    }

And the insightManager.CaseSummary(x.caseId) code returns an instance of a class that contains a nullable DateTime.

The problem is that in the serialisation/deserialistion process the date loses an hour, which I asume is some kind of UTC offset. Which is kind of anoying because I only want the date portion anyway, so it looks like all of dates are the day before they really are.

I’ve seen plenty of posts bout fixing tis in javascript but I’m not sure how to apply them when both parts of my code are using “standard” serilasers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:14:53+00:00Added an answer on June 3, 2026 at 5:14 pm

    So, I found the answer in the end. Essentially I just need to call .ToLocalTime() after the dates are deserialised to ensure I get the results I need. A very good explanation of why here http://www.west-wind.com/weblog/posts/2008/Sep/03/Watch-out-for-Date-Kind-in-JSON-Deserialization

    But, in short, when you serialise to JSON dates are always converted into UTC time so the date you get back from a deserialise will always be a UTC date so you need to convert it back to local time.

    Just in case anyone else has this problem, I have adapted my ParseResponseForObject<T> function to always use local time for any DateTime or DateTime?…

        public static T ParseResponseForObject<T>(string response)
        {
            var javaScriptSerializer = new JavaScriptSerializer();
            try
            {
                var obj = javaScriptSerializer.Deserialize<T>(response);
    
                var props = obj
                    .GetType()
                    .GetProperties(BindingFlags.Instance | BindingFlags.Public);
    
                foreach (var pi in props)
                {
                    if (pi.PropertyType == typeof(DateTime))
                    {
                        var origDt = (DateTime)pi.GetValue(obj, null);
                        pi.SetValue(obj, origDt.ToLocalTime(), null);
                    }
                    else if (pi.PropertyType == typeof(DateTime?))
                    {
                        var origDt = (DateTime?)pi.GetValue(obj, null);
    
                        if (origDt.HasValue)
                        {
                            pi.SetValue(obj, origDt.Value.ToLocalTime(), null);
                        }
                    }
                }
    
                return obj;
            }
            catch (Exception ex)
            {
                throw new Exception(response, ex);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have a look at the following code to find X^y. /* Find exponent in
I have a modular software, one module must be a webserver that accept REST
Have the following code. The height is variable so the height of the floating
I have a file that contains some JSON with an extension of .json. I
suppose I have the following source table (called S): name gender code Bob 0
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have I understod the following right? font-family:sans-serif; Above will result in the default sans-serif
Have you guys had any experiences (positive or negative) by placing your source code/solution
I have two tables as follows: I have a RatingsTable that contains a ratingname

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.