5

Is there any JavaScript library that takes Java's SimpleDateFormat pattern and parses a date/time string into a Date object?

For example, given "2010-12-20" and "yyyy-MM-dd", the function would parse "2010-12-20" and return a JavaScript Date.

I noticed that jQuery UI's Date Picker can format and parse a date string, but it doesn't work with a time string.

Thanks.

Tom Tucker
  • 11,676
  • 22
  • 89
  • 130

4 Answers4

1

I would try the Datejs library: http://www.datejs.com/

jmbucknall
  • 2,061
  • 13
  • 14
  • The format strings used by datejs (see http://code.google.com/p/datejs/wiki/FormatSpecifiers) are not compatible with SimpleDateFormat. – Stephen C Jan 22 '11 at 23:45
  • 2
    Are you saying that Datejs's parseExact function called like this 'var myDate = Date.parseExact("2010-12-10", "yyyy-MM-dd");' doesn't work? It seems to me it covers the OP's example and may in fact cover a lot more that he needs. Maybe I should have been a little forthcoming in my answer. – jmbucknall Jan 23 '11 at 00:07
1

This might be what you want: http://www.timdown.co.uk/code/simpledateformat.php

limc
  • 39,366
  • 20
  • 100
  • 145
0

I guess you are not the only looking for it. See this thread that has similar content. In the end, the author had to role his/her own but there are some good suggestions in there that might be of benefit.

Community
  • 1
  • 1
gbvb
  • 866
  • 5
  • 10
0

Google's GWT project has a class to do this. http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/i18n/client/DateTimeFormat.html Probably no small job to get that into a standalone javascript, though.

Rich MacDonald
  • 895
  • 6
  • 5