JavaScriptSerializer serialization time processing example _ javascript skills

Source: Internet
Author: User
After the JavaScriptSerializer serialization time, the time will be serialized into nhexadecimal ghost data. The following is an example, A friend who needs to know about the time serialized by JavaScriptSerializer will serialize the time into the native ghost data, so he checked the material and sat down the record.

Suppose list = News List <Text> () {New Text () {id = 1, date = '2017-03-11 00:00:00. 000 '}}
</Text>

JavaScriptSerializer serializable = new JavaScriptSerializer (); string json = serializable. serialize (new {total = total, rows = list}); // use a regular expression to replace the serialized time json = System. text. regularExpressions. regex. replace (json, @ "\/Date \ (\ d +) \/", match => {DateTime dt = new DateTime (1970, 1, 1); dt = dt. addMilliseconds (long. parse (match. groups [1]. value); dt = dt. toLocalTime (); return dt. toString ("yyyy-MM-dd HH: mm: ss") ;}); return json;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.