views:

329

answers:

2

I have a problem with Jquery function getJSON, the action url does not trigger because one of the parameter i am passing is a javascript date but the action expects c# DateTime..

Is it possible to format the Javascript Date to make it compatible for c# DateTime?

+3  A: 

I would suggest using the Datejs library (http://www.datejs.com/). From my limited experience with it it's fantastic.

ScottD
+2  A: 

Use this function taken from the Mozilla Date documentation:

/* use a function for the exact format desired... */
function ISODateString(d){
 function pad(n){return n<10 ? '0'+n : n}
 return d.getUTCFullYear()+'-'
      + pad(d.getUTCMonth()+1)+'-'
      + pad(d.getUTCDate())+'T'
      + pad(d.getUTCHours())+':'
      + pad(d.getUTCMinutes())+':'
      + pad(d.getUTCSeconds())+'Z'
}

.NET will have no problem handling an ISO formatted date. You can use DateTime.Parse(...) to handle the ISO formatted string.

Dan Herbert