I am returning a JSON object from my web service method. The object has some dates in it and so the generated JSON is like the following:
{"d": [
{"PeriodID":8,"Period":"072011","BeginDate":"\/Date(1294268400000)\/"},
{"PeriodID":2,"Period":"052011","BeginDate":"\/Date(1293836400000)\/"}
]}
I am trying to convert this data in a string to be added as <option> elements in an HTML select. This is my code:
var rtypes = data.d;
$.each(rtypes, function (key, value) {
var text = value.Period + " - " + "from " + eval(value.BeginDate.slice(1, -1));
var option = $("<option></option>").attr("value", value.PeriodID).text(text);
$('#rpCombo').append(option);
});
Now the questions:
- Can I format the date contained in the
Periodfield (e.g. 072011) as a "July 2011"? - How can I convert the result of
eval(value.BeginDate.slice(1, -1))that is for instance something like "Wed July 14......" into something like "14/07/2011"?
Thanks for helping