If you know that the supplied string str
has dd/mm/yyyy
format then you can just use
var date= new Date( str.split( "/" ).reverse() );
Date.parse
is guaranteed to parse a simplified ISO-8601 format. Whether other formats will be recognized is up to the implementation. But note that the code above passes year, month and day as numbers to the constructor, so it hasn't to parse it again.
Edit:
My code above is wrong. It just works for me because the reversed array will be converted to the string "2014,01,25", which Mozilla's Date.parse
happens to accept. You need to pass the arguments separately as @Alex Kudryashev and @le_m have suggested. Even
Date.prototype.constructor.apply( null, array )
won`t work, because the Date constructor behaves differently when invoked as a function.