Javascript String formatTime(template)
String.prototype.formatTime= function(template){ var template = template || '{0}?{1}?{2]?{3]?{4}?{5}?'; var ary = this.match(/\d+/g); tmplate = template.replace(/{(\d+)}/g, function(){ var index = arguments[1]; this.result = ary[index];// w w w . ja v a 2 s. c om this.result = this.result || '00'; this.result.length<2? this.result = '0'+ this.result:null; return this.result; }); return tmplate; }