2

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) ?

Oded
  • 489,969
  • 99
  • 883
  • 1,009
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • possible duplicate of [Converting .NET DateTime to JSON](http://stackoverflow.com/questions/1016847/converting-net-datetime-to-json) – Oded Dec 31 '11 at 10:23

3 Answers3

1

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.

Community
  • 1
  • 1
Richard Harrison
  • 19,247
  • 4
  • 40
  • 67
  • how can i create this format in C# server side? Fri Jun 19 2009 11:04:53 GMT+0300 (Jerusalem Daylight Time)" – Elad Benda Dec 31 '11 at 10:53
0

You present it on the client side itself using the following javascript code

var dt = new Date(1318319100000);
tempDate = dt.getDate();
tempMonth = dt.getMonth()+1;
tempHour = dt.getHours();
tempMin = dt.getMinutes();
tempSec = dt.getSeconds();

var currentDate = tempDate +"/"+tempMonth+"/"+dt.getFullYear();
var currentTime = tempHour + ":" + tempMin + ":" + tempSec;

var dtTime = currentDate +" "+currentTime; 

You can put all these steps within a function and then call it by passing the parameter that is the time stamp to be converted and return the dtTime value and place it in a text box or a innerHTML of a div.

Hope this helps you.

AmGates
  • 2,127
  • 16
  • 29
0

You can simply convert the time using javascript. Only thing you need is if you want to get the timezone added as per your client. You can get an example here: Also the source to conver the time along with timezone is in the source of the page.

http://www.thewebgoodies.com/unix-time-conversion/

ddsh79
  • 119
  • 5