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

  • Home
  • SEARCH
  • 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 175099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:38:22+00:00 2026-05-11T13:38:22+00:00

I have a controller action that effectively simply returns a JsonResult of my model.

  • 0

I have a controller action that effectively simply returns a JsonResult of my model. So, in my method I have something like the following:

return new JsonResult(myModel); 

This works well, except for one problem. There is a date property in the model and this appears to be returned in the Json result like so:

'\/Date(1239018869048)\/' 

How should I be dealing with dates so they are returned in the format I require? Or how do I handle this format above in script?

  • 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. 2026-05-11T13:38:23+00:00Added an answer on May 11, 2026 at 1:38 pm

    Just to expand on casperOne’s answer.

    The JSON spec does not account for Date values. MS had to make a call, and the path they chose was to exploit a little trick in the javascript representation of strings: the string literal ‘/’ is the same as ‘\/’, and a string literal will never get serialized to ‘\/’ (even ‘\/’ must be mapped to ‘\\/’).

    See http://msdn.microsoft.com/en-us/library/bb299886.aspx#intro_to_json_topic2 for a better explanation (scroll down to ‘From JavaScript Literals to JSON’)

    One of the sore points of JSON is the lack of a date/time literal. Many people are surprised and disappointed to learn this when they first encounter JSON. The simple explanation (consoling or not) for the absence of a date/time literal is that JavaScript never had one either: The support for date and time values in JavaScript is entirely provided through the Date object. Most applications using JSON as a data format, therefore, generally tend to use either a string or a number to express date and time values. If a string is used, you can generally expect it to be in the ISO 8601 format. If a number is used, instead, then the value is usually taken to mean the number of milliseconds in Universal Coordinated Time (UTC) since epoch, where epoch is defined as midnight January 1, 1970 (UTC). Again, this is a mere convention and not part of the JSON standard. If you are exchanging data with another application, you will need to check its documentation to see how it encodes date and time values within a JSON literal. For example, Microsoft’s ASP.NET AJAX uses neither of the described conventions. Rather, it encodes .NET DateTime values as a JSON string, where the content of the string is /Date(ticks)/ and where ticks represents milliseconds since epoch (UTC). So November 29, 1989, 4:55:30 AM, in UTC is encoded as ‘\/Date(628318530718)\/’.

    A solution would be to just parse it out:

    value = new Date(parseInt(value.replace('/Date(', '').replace(')/',''), 10)); 

    However I’ve heard that there is a setting somewhere to get the serializer to output DateTime objects with the new Date(xxx) syntax. I’ll try to dig that out.


    The second parameter of JSON.parse() accepts a reviver function where prescribes how the value originally produced by, before being returned.

    Here is an example for date:

    var parsed = JSON.parse(data, function(key, value) {   if (typeof value === 'string') {     var d = /\/Date\((\d*)\)\//.exec(value);     return (d) ? new Date(+d[1]) : value;   }   return value; }); 

    See the docs of JSON.parse()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following controller action and test. I'm new to testing with Shoulda
I have the following route defined routes.MapRoute( ItemName, {controller}/{action}/{projectName}/{name}, new { controller = Home,
I have an integer output from a private controller action that I would like
I have a Controller Action that is trying to return plain text to an
In MVC 3 project, I have a Controller action that returns a View. Let's
I have a controller action that is being executed by a link that was
I have a HTML form, and I have a Controller Action that accepts the
If I have an ASP.NET MVC controller action that is called from a jQuery
Using Rails v2.1, lets say you have an action for a controller that is
I have a controller action which I would like to call another controller action.

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.