I wrote a web site.
- The client sends an ajax request to the server
- The server sends back a
DateTime - The client should print it to the UI
using chrome console I see the client gets:
SentTime: "/Date(1318319100000)/"
How can I manipulate the data in client side to be printed nicely?
Is it preferable to do this on server side (meaning sending only strings) ?
That’s a unix timestamp (see http://www.unixtimestamp.com/index.php). See Convert a Unix timestamp to time in Javascript
Personally I’d recommend that the server should return an ISO format date string or an already formatted date string.
Whether it is preferable depends largely on your preferences. For my preference I like the server to do most of the work and take the responsibility for the presentation of data as often it will have a better grasp of the context. Not always true, and it is arguable that a client can take responsibility for the display of items using a standard format conversion.
To produce an ISO format string use dateTimeVar.ToString(“s”), for a culture aware version using ToString(“f”). See Standard Date and Time Format Strings.