I've the next problem:
when I recieve date from server, I want to format it via datepicker, but datepicker throws exceptions, cause it can't parse the date.
here is my date, whcih comes from server(obj.value):
08.20.2012 19:01:32
and here is code via which I try to parse this date:
$.datepicker.formatDate('dd.MM.yy', new Date(obj.value));
I use MM cause I need the full name of the month.
and here is output after parsing:
NaN.NaN.NaN
so how to get rid of this exception?
You need to change you date (obj.value) to a valid JavaScript date format. Best if you can do on the server side.
If you want to do it on client side you need to replace . with / so you get 08/20/2012 19:01:32 instead of 08.20.2012 19:01:32.
new Date(obj.value.replace(/\./g, '/'))
You are trying to parse a date in JavaScript, this is completely implementation depend. It seems that many browsers are unable to parse your provided string. You will have to do either of two thing:
Also see this answer: Why does Date.parse give incorrect results?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With