首页 > 编程知识 正文

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

时间:2023-05-03 19:02:13 阅读:107356 作者:643

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 );

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。