开发者

How to convert a jquery DatePicker DateTime to pass to Controller as DateTime

开发者 https://www.devze.com 2023-03-02 01:30 出处:网络
I am having the following piece of code: data: { myDate: Date.parseE开发者_开发问答xact(mylastSelectedDate, \"yyyy/MM/dd\"),

I am having the following piece of code:

 data:
                 {
                     myDate: Date.parseE开发者_开发问答xact(mylastSelectedDate, "yyyy/MM/dd"),
                     ID : ID
                 },

In my controller, myDate is DateTime.

In debug mode, mylastSelectedDate has the value:

Tue May 03 2011 00:00:00 GMT+0400 (Arabian Standard Time) { _orient=1, _is=false}

However, it seems that myDate is null despite the mylastSelectedDate value. What is wrong with my code?


Read the documentation, the second argument to the Date.js parseExact method is the format of the date string being passed to the method.

Converts the specified string value into its JavaScript Date equivalent using the specified format (string) or formats (array). The format of the string value must match one of the supplied formats exactly.

The format in the example is nothing like what is being passed in:

Tue May 03 2011 00:00:00 GMT+0400 (Arabian Standard Time) { _orient=1, _is=false}

is equivalent to something like:

'ddd MMM dd yyyy hh:mm:ss' and so on

You may need to re-format the date since I don't know if Date.js can handle the parts after the timezone, which means you'll need to parse it. Having done that, you might as well create a date object yourself.

Parsing the above should only require a few lines of code.

0

精彩评论

暂无评论...
验证码 换一张
取 消