Javascript String formatDate()
'use strict';//w ww. ja v a2 s. c o m var moment = moment || {}; String.prototype.formatDate = function () { return moment(this.toString()).format('LL'); };
String.prototype.formatDate = function() { var pattern = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$"); var match = pattern.exec(this); if (match && match[1] && match[2] && match[3]) { return match[1] + "-" + match[2] + "-" + match[3]; }//from w ww .ja v a2 s . co m return this; };