views:

2027

answers:

2

So I've finally got my WCF service setup and talking to browser via ASP.NET AJAX. But I have found that when I populate a html table with my data... the datetime format looks like this:

Fri Jan 02 2009 15:27:12 GMT-0500 (Eastern Standard Time)

On the server I am using the .NET DateTime format. Should I use something else and do the work on the server? or is there any easy way via JavaScript (ASP.NET AJAX or jQuery) to fix this on the client?

I like just the 'Jan 02 2009 15:27:12' part. I guess I could use substring(), but am I missing something?

MORE INFO: I figured out that the data coming back to the browser was a valid JavaScript Date object.
So you can use any of the native JavaScript Date functions to deal with the value or... You can use .toString().substring() and trim off what you don't want.

A: 

When you print the value you should be able to print it in the browsers native format,

Or if you want t deside it in the webservice return a string with return yourDatetimeVaiable.Tostring(cultureinfo);

or something simular to that...

Richard L
+5  A: 

Since you are using ASP.NET Ajax, you can call format on your Date object in javascript, similar to how you would in .NET. for example:

var myDateString=myServiceObject.Date.format("d");//short date pattern

or a custom pattern...

var myDateString2=myServiceObject.Date.format("yyyy/mm/dd");//some custom pattern..

Found a list of supported format strings here: http://seejoelprogram.wordpress.com/2008/08/07/supported-number-and-datetime-format-strings-in-aspnet-ajax/

markt
+1 - I like this method.
tyndall