我想转换1,2,3,..9,10,11,12...24为01,02,03,...09,10,11,12,...24. 我尝试了这些解决方案。这些都没有解决我的目的:
我正在做一个Angular项目,我在Typescript做这个。这是我的代码:
monthpikcer.component.ts
monthSlice() {
let monthStartingIndex = 0;
monthStartingIndex = ("0" + monthStartingIndex).slice(-2); //error
let monthEndingIndex = 24;
for(monthStartingIndex =0; monthStartingIndex < monthEndingIndex; monthStartingIndex++) {
...
}
}
但是对于 line monthStartingIndex = ("0" + monthStartingIndex).slice(-2),我收到一个错误:
类型“字符串”不可分配给类型“数字”。
我希望它是01, 02, 03...10,11,12,13...24。请告诉我如何在不更改变量数据类型的情况下执行此操作,因为稍后我必须对它们进行一些算术运算。