C # uses LINQ processing to return JSON display with datetime type data/date (XXXXX)/

Source: Internet
Author: User

Previous projects have been encountered with a database with datetime type data returned to the foreground will become a timestamp

It's obviously not what we want.

So I was in the original project selected in the front-end JS format date (XXXX) Form of processing now I want to be a little stupid

Today brainwave thought that it would be possible to turn the DateTime into a string on the server to return to the result with this article

Service side:

1Datagetentities context =Newdatagetentities ();2             varQuerytyphoon = context. T_typhoonpaths.where (i = I.typhooncode = =Typhooncode). ToList ();3Newtonsoft.Json.Converters.IsoDateTimeConverter ISO =NewNewtonsoft.Json.Converters.IsoDateTimeConverter ();4Iso. DateTimeFormat ="YYYY-MM-DD Hh:mm:ss";5 6             varPath = ( fromPinchQuerytyphoon7                           Select New8                           {9 P.id,Ten P.air_pressure, One P.dottype, A P.latitude, - P.longitude, - P.move_direction, the P.move_speed, - P.seven_wind, - P.ten_wind, - P.typhooncode, + P.typhoonname, - P.wind_power, + P.wind_speed, A P.wind_time at                           }); -             returnContent (jsonconvert.serializeobject (path, ISO));

It is important to note that the JSON returned at this time is actually a string and not an object, so you need to turn around at the front end:

1      var tdata = json.parse (data);

C # uses LINQ processing to return JSON display with datetime type data/date (XXXXX)/

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.