Javascriptserializer indicates the scale when serializing datetime. In JSON, the scale is represented as: \/date (315547200000) \/a closure is made with V, and the scale of date is enclosed in brackets, the scale is the number of milliseconds after which the time tick is answered. the end time of the scale calculation is UTC, which starts at midnight on January 1, January 1, 1970,
Note that the start time and end time are UTC time.Program:
Customer cs = new customer ();
CS. Birthday = new datetime (1980, 1, 1, 12, 0, 0 );
CS. Name = "Steven ";
CS. Sex = true;
Javascriptserializer JS = new javascriptserializer ();
String output = Js. serialize (CS );
Customer Cust = Js. deserialize (output, typeof (customer) as customer;
If (Cust! = NULL)
{
Txtbirthday. Text = Cust. Birthday. value. tostring ();
}
In this case, the date after serialization is not 12:00:00, but a time obtained from UTC time, which may be 4:00:00, in this way, the UI display will bring consistency issues!
Other processing is very simple. Before serialization, convert the local time to UTC time, and then convert the UTC time to the local time after deserialization. Code :
Customer cs = new customer ();
CS. Birthday = new datetime (1980, 1, 1, 12, 0, 0). touniversaltime ();
CS. Name = "Steven ";
CS. Sex = true;
javascriptserializer JS = new javascriptserializer ();
string output = Js. serialize (CS);
customer Cust = Js. deserialize (output, typeof (customer) as customer;
If (Cust! = NULL)
{< br>
txtbirthday. TEXT = Cust. birthday. value. tolocaltime (). tostring ();
}