js格式化日期年月日,js当前时间格式化

interfacedate { format : (this : date,fmt: string ) string } date.prototype.format=function ) fmt } const this this.getHours ) ]、[/] h ) /、this.getHours )、this.getseconds(] ()、[/q ] /、math.floor ) this.getmillisecondder ) ] if(/)/.test ) fmt ) ) fmt=fmt.replace ) regexp.$1,this.getfullyear.toststrttostttttttttttttresttttttttttttttexprext key ) ) if ) key.test ) fmt ) ) fmt=fmt.replace ) regexp.$1,)1==regexp.$1. lenen ed val.tostring (: ) }; ); return fmt; }console.info(newdate ).format (yyyy-mm-ddhh : mm : ss ) ); console.info(newdate ).format (yyyy/mm/ddhh : mm : ss ‘ ); console.info(newdate ).format ) ‘ yyyy年MM月dd日第q季); console.info(newdate ).format ) ‘ yyyymmddhhmmss-s ‘ ); () ) )/**@param(string ) val )/constformat2=s=) 00${s} ).substr ) s.length ); /**格式日期为yyyy-mm-ddhh : mm : ss * @ return { string } */date.prototype.tocommonstring=function { constd } const yyyy=d.getFullYear ().toString ); constmm=format2((d.getmonth ) )1).toString ); const DD=format2(d.getdate (.tostring ) ); consthh=format2(d.gethours ().toString ) ); constmm=format2(d.getminutes ().toString ) ); constss=format2(d.getseconds ().toString ) ); return ` $ { yyyy }-$ { mm }-$ { DD } $ { hh } : $ { mm } 3360 $ { ss } `; (;/* * * yyymmddhhmmss * @ return { string } */date.prototype.toid string=function ({ constd=this; const yyyy=d.getFullYear ().toString ); constmm=format2((d.getmonth ) )1).toString ); const DD=format2(d.getdate (.tostring ) ); consthh=format2(d.gethours ().toString ) ); constmm=format2(d.getminutes ().toString ) ); constss=format2(d.getseconds ().toString ) ); return ` $ { yyyy } $ { mm } $ { DD } $ { hh } $ { mm } $ { ss } `; (; () ); console.log(newdate ).toCommonString ); console.log(newdate ).toIDString );

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注