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.

0

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

The format strings used by datejs (see code.google.com/p/datejs/wiki/FormatSpecifiers) are not compatible with SimpleDateFormat.
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.
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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.