I have a situation which keeps coming up all the time when I think it's over. It's a ASP.NET project but I am not using ASP.NET AJAX elemets and any server side elements in design part. I am using ASP.NET to handle database operations and using jQuery elements in design, also using only jQuery AJAX to send and receive data from UI.
I have a method which runs when an ajax call is made and returns an object class with a DateTime element in it. I need to use what returns in a javascript function to show on the screen. I don't want to use JSON.NET or anything else to serialize the returning class beacuse ASP.NET does all the conversions when I return an object class, itself already.
So, my problem is I am getting a long date format which is not compatible with any javascript function and none of moment.js or date.js libraries supporting that format. The output of the datetime asp.net object in javascript is like:
"Sun Aug 11 2013 00:00:00 GMT +0300 (Turkey Daylight Time)"
I looked for some info about that for days and didn't find any questions or articles explaining how to cast returning datetime properly. May be not looking for the right thing...
I know that I can create a JSON string and send that class' values with it. I've been there. But my head starts hurting when I start to question the logic of asp.net automatically serializing returning classes and returning a non useful datetime object.
So, I decided to hear your opinions on that matter. What is the best way of dealing datetime conversion issues in asp.net?
- I can change the DateTime object to a simple string and get the value as string and cast it to datetime in asp.net and return the same class with a string like a date object, but that is creating other casting problems in javascript side (DD/MM/YYYY and MM/DD/YYYY issues).
- I can look for a way to properly cast the returning datetime format of asp.net to javascript form (which I believe is after a lot of research is quite impossible)
- I can create my class which would include a long int object and cast (serialize) that datetime object to JSON format before sending as a return call in asp.net method.
Which one of these is better and why, and is there another, better way to do this?
Thanks...