JavaScript通过Date-Mask将日期转换成字符串的方法

前端之家收集整理的这篇文章主要介绍了JavaScript通过Date-Mask将日期转换成字符串的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了JavaScript通过Date-Mask将日期转换成字符串的方法分享给大家供大家参考。具体实现方法如下:

cutOff) ? '19' : '20') : '20'; tempDate += sDate.substr(index + 1); sDate = tempDate; return $1 + $2 + $2; }); sParsed = ('YYYY/MM/DD').replace(/YYYY|MM|DD/g,function(m){ return (sFormat.indexOf(m) + 1) ? sDate.substr(sFormat.indexOf(m),m.length) : ''; }); if (sParsed.charAt(0) == '/') { // if no year specified,assume the current year sParsed = (new Date().getFullYear()) + sParsed; } if (sParsed.charAt(sParsed.length - 1) == '/') { // if no date,assume the 1st of the month sParsed += '01'; } // should end up with 10 characters.. return ( sParsed.length == 10 ) ? sParsed : ''; };

希望本文所述对大家的javascript程序设计有所帮助。

原文链接:https://www.f2er.com/js/54079.html

猜你在找的JavaScript相关文章