1

I've seen other examples but I am looking for this specific format if possible?.

Calibre2010
  • 3,549
  • 9
  • 24
  • 35

4 Answers4

7

Here is a quick format from JSON date format to required date format using jQuery:

For a JSON date string like:

/Date(1339439400000)/

try:

var newFormattedDate = $.datepicker.formatDate('mm/dd/yy', new Date(Date(your_JSON_date_string)));

and it will result in date like this: 09/14/2012

j0k
  • 22,303
  • 28
  • 77
  • 86
nsingh
  • 79
  • 1
  • 2
6
    function formatJsonDate(jsonDate) {
        return (new Date(parseInt(jsonDate.substr(6)))).format("dd/mm/yyyy");
    };    

    var testJsonDate = formatJsonDate('/Date(1224043200000)/');

    alert(testJsonDate);
Thulasiram
  • 8,258
  • 8
  • 45
  • 52
2

There is no "json date format". json only returns strings.

Date javascript object can parse a variety of formats. See the documentation.

You can do:

var myDate = new Date(myDateAsString);
Vincent Mimoun-Prat
  • 27,630
  • 15
  • 77
  • 123
1

There are a few suggestions in the answers to this post -- How do I format a Microsoft JSON date?

If those examples aren't working, you can just format it manually. Here's a quick fiddle that demonstrates it -- http://jsfiddle.net/dhoerster/KqyDv/

$(document).ready(function() {
    //set up my JSON-formatted string...
    var myDate = new Date(2011,2,9);
    var myObj = { "theDate" : myDate };
    var myDateJson = JSON.stringify(myObj);

    //parse the JSON-formatted string to an object
    var myNewObj = JSON.parse(myDateJson);

    //get the date, create a new Date object, and manually format the date string
    var myNewDate = new Date(myNewObj.theDate);
    alert(myNewDate.getDate() + "/" + (myNewDate.getMonth()+1) + "/" + myNewDate.getFullYear());
});
Community
  • 1
  • 1
David Hoerster
  • 27,923
  • 8
  • 65
  • 100