Created
December 1, 2011 11:14
-
-
Save mrmarcondes/1415935 to your computer and use it in GitHub Desktop.
Exercício sobre expressões regulares
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.convertDateFormat = function() { | |
var pattern = /^(\d{1,2})\/(\d{1,2})\/(\d{4})/; | |
var str = ""; | |
for (var i = 0; i < this.length; i++){ | |
str += this[i]; | |
} | |
return str.match(pattern)[3] + '-' + str.match(pattern)[2] + '-' + str.match(pattern)[1]; | |
}; | |
var a = "30/10/2000"; | |
console.log(a.convertDateFormat()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment