How can I convert string to datetime with format specification in JavaScript?

datetime, javascript, type-conversion

Solution

I think this can help you: http://www.mattkruse.com/javascript/date/

There's a `getDateFromFormat()` function that you can tweak a little to solve your problem.

Update: there's an updated version of the samples available at javascripttoolbox.com

Problem

How can I convert a string to a date time object in javascript by specifying a format string? I am looking for something like: ``` var dateTime = convertToDateTime("23.11.2009 12:34:56", "dd.MM.yyyy HH:mm:ss"); ```

Original source