当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JavaScript指定日期格式化

JavaScript指定日期格式化

2019年07月25日  | 移动技术网IT编程  | 我要评论
formatdatatostring:function (dates, formats) {
            var o = {
                "m+": dates.getmonth() + 1, //月份 
                "d+": dates.getdate(), //日 
                "h+": dates.gethours(), //小时 
                "m+": dates.getminutes(), //分 
                "s+": dates.getseconds(), //秒 
                "q+": math.floor((dates.getmonth() + 3) / 3), //季度 
                "s": dates.getmilliseconds() //毫秒 
            };
            if (/(y+)/.test(formats)) formats = formats.replace(regexp.$1, (dates.getfullyear() + "").substr(4 - regexp.$1.length));
            for (var k in o)
                if (new regexp("(" + k + ")").test(formats)) formats = formats.replace(regexp.$1, (regexp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return formats;

}
//调用
formatdatatostring(new date("2019/07/24"),"yyyy-mm-dd")

  

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网