2

I have set a column to column type "Date" and the json response from listData.svc for this column is in this format "Created": "/Date(1377683175000)/" , can someone suggest how to convert this format to string?

I have tried new Date(Time).toLocaleString (Time is the variable that hold the date/time field) but doesn't work.

1

If you are developing javascript for SharePoint and can use its javascript libraries then it might be a good idea to be using standart approach which take care of all the rest

var date = new Date();
var arg = { date: date };
var str = Sys.Serialization.JavaScriptSerializer.serialize(arg);// "{"date":"\/Date(1377757755979)\/"}"
var newObject = Sys.Serialization.JavaScriptSerializer.deserialize(str);
var newDate = newObject.date; // Date {Thu Aug 29 2013 10:29:15 GMT+0400}

The class is a part of Microsoft Ajax Library so it is a good idea to use it whenever you want to communicate with standart Microsoft Web Services.

  • Do I have to load microsoftajax.js or it is included out of the box with SharePoint 2010? – user1758952 Aug 30 '13 at 3:06
  • Included already. – Sergey Prosin Aug 30 '13 at 5:40
0
        private static DateTime ConvertJsonTimestamp(double jsonTime)
    {

        var baseTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);

        return baseTime.AddSeconds(jsonTime);

    }

pass in your Time variable to this method and you will get a .net date back. There are other methods, but most requires som third party library like Newtonsoft

0

As part of .Net Framework at least two options are available:

Example

string dateString = @"""\/Date(1377683175000)\/""";
var serializer = new JavaScriptSerializer();
var date = serializer.Deserialize<DateTime>(dateString);  //returns {28.8.2013 9:46:15}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.