js 设置固定位数。时间月日小时分钟秒

时间:2021-08-21 20:04:25   收藏:0   阅读:29

function fix(num, length) {
return (‘‘ + num).length < length ? ((new Array(length + 1)).join(‘0‘) + num).slice(-length) : ‘‘ + num;
}

fix(1234, 8);
// "00001234"
fix(1234, 2);
// "1234"

原文:https://www.cnblogs.com/wx18638101223/p/15169619.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!