Alex Rivera | Logout

Convert Javascript Date to ASP.NET Date format

Asked 2012-09-12T09:38:08.317
8

I would like to convert a Javascript date format to ASP.NET date format.

2012-09-10 12:00PM to /Date(1347442050050-0700)/

Because I'm passing it back to the server. I got the ASP.NET format from the request I did on the server, then convert it to Javascript date using moment.js:

moment("/Date(1347442050050-0700)/").format("YYYY-MM-DD hh:mmA");

Is there a way to do this?

Edit
Report

2 Answers

3

You can add the function to the moment prototype so that it's a little more portable.

http://jsfiddle.net/timrwood/qe8pk/

moment.fn.toASP = function () {
    return '/Date(' + (+this) + this.format('ZZ') + ')';
}
answered 2012-09-12T17:12:05.177
1

If you want to send a date back to an ASP.NET ASMX web service where the RPC method receives a DateTime object, this may be helpful: https://stackoverflow.com/a/12973157/1145963

answered 2012-10-19T11:32:18.870

Your Answer