date类型转换为string类型: date.prototype.format = function(fmt) { //author: meizz var o = { "m+" : this.getmonth()+1, //月份 "d+" : this.getdate(), //日 "h+" : this.gethours(), //小时 "m+" : this.getminutes(), //分 "s+" : this.getseconds(), //秒 "q+" : math.floor((this.getmonth()+3)/3), //季度 "s" : this.getmilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt=fmt.replace(regexp.$1, (this.getfullyear()+"").substr(4 - regexp.$1.length)); for(var k in o) if(new regexp("("+ k +")").test(fmt)) fmt = fmt.replace(regexp.$1, (regexp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); return fmt; } //将data转换为yyyy/mm/dd类型 new date(data).format("yyyy/mm/dd");
以上就是js控制date类型转换为string类型实例的详细内容。
