Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deserialize "/Date(1309498021672)/" in to DateTime

I have a object that I serialize with the JavaScriptSerializer and output it in a javascript variable.

A property on this object is a date which gets converted to eg. "/Date(1309498021672)/"

I then send this value to the server via a ui wcf service call. I want to deserialize this value in to a DateTime object.

How can I do this? I am working with asp.net c# web application.

like image 577
amateur Avatar asked Dec 10 '22 07:12

amateur


1 Answers

Your string format is just a little off, but this will deserialize to a proper date.

var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string json = "\"\\/Date(1309498021672)\\/\"";
DateTime date = serializer.Deserialize<DateTime>(json);
// date is 7/1/2011 5:27:01 AM
like image 195
Anthony Pegram Avatar answered Dec 25 '22 18:12

Anthony Pegram