Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datepicker parsing date issue

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?

like image 297
Helgus Avatar asked Dec 14 '25 05:12

Helgus


2 Answers

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, '/'))
like image 57
fredrik Avatar answered Dec 15 '25 18:12

fredrik


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:

  • Provide a valid string.
  • Call a Date constructor.

Also see this answer: Why does Date.parse give incorrect results?

like image 27
Styxxy Avatar answered Dec 15 '25 17:12

Styxxy