Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

3 Answers

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.

share|improve this answer
 
Do I have to load microsoftajax.js or it is included out of the box with SharePoint 2010? –  user1758952 Aug 30 at 3:06
 
Included already. –  Sergey Prosin Aug 30 at 5:40
        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

share|improve this answer

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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