是否可以将数字array
解析为typescript
中的日期字符串?
这就是我在C#中的做法:
int[] date = { 2017, 10, 20 };
public string convert(dynamic date)
{
return string.Format("{0}/{1}/{2}", date[1], date[2], date[0]);
}
在typescript
/ javascript
中有任何建议吗?
答案 0 :(得分:2)
与您的C#代码最相似的可能是:
const date = [2017, 10, 20];
convert(date: number[]): string {
return `${date[0]}/${date[1]}/${date[2]}`;
}
答案 1 :(得分:1)
您可以尝试以下操作:
let date = [2017, 10, 20]
const convert = function(d){
return d.join('/')
}
或者,对于更通用的解决方案,您应该检查Date内置对象。