指定格式时间,月份天数前补零

antd DatePicker选中的时间,可以用format格式化:
https://blog.csdn.net/weixin_43915401/article/details/112880693
js获取时间方法:
https://blog.csdn.net/weixin_43915401/article/details/114014926

js生成指定格式的时间,只能自己拼,就。。。补充一下,填充字符串的方法吧。
padStart(2,'0')2位字符串,不足两位的,在前面补零。

let date = new Date();
YYYY-MM-DD = date.getFullYear() + '-'
        + (date.getMonth() + 1).toString().padStart(2, '0') + '-'
        + (date.getDate()).toString().padStart(2, '0');

猜你喜欢

转载自blog.csdn.net/weixin_43915401/article/details/125100465