个位数转十位数

padStart

应用场景: 日期format

1
2
3
4
5
6
// Task: Turn new Date() to '20250312'
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
const day = new Date().getDate()

const resultDate = `${year}${month.toString().padStart(2, '0')}${day.toString().padStart(2, '0')}`

本文作者: 孟 虎
本文链接: https://menghu1994.github.io/blog/uncategorized/FrontEnd/Gists/padStart/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!