getMinutes()0-9 - 如何使用两个数字? [英] getMinutes() 0-9 - how to with two numbers?
本文介绍了getMinutes()0-9 - 如何使用两个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var date = "2012-01-18T16:03";
var date = new Date(date);
console.log(date.getMinutes());
console.log(date.getMinutes().length)
返回3.
- 如何让它返回'03'?
- 为什么
.length
返回undefinded?
- How do I make it return '03'?
- Why does
.length
return undefinded?
我试过这个,但是没有用:
I tried this, but it did not work:
如果 strlen == 1
然后 num =('0'+ num);
推荐答案
var date = new Date("2012-01-18T16:03");
console.log( (date.getMinutes()<10?'0':'') + date.getMinutes() );
这篇关于getMinutes()0-9 - 如何使用两个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文