如何在hour is < 10
将小时附加“0”时获得小时数?如何在Selenium IDE中使用javascript格式化当前时间
对于例:
javascript{new Date().getHours() +":" + new Date().getMinutes())}
结果:9:20 ...
我需要格式化 “09:20”。
如何在hour is < 10
将小时附加“0”时获得小时数?如何在Selenium IDE中使用javascript格式化当前时间
对于例:
javascript{new Date().getHours() +":" + new Date().getMinutes())}
结果:9:20 ...
我需要格式化 “09:20”。
var d = new Date();
console.log(
(d.getHours() < 10 ? '0' : '') + d.getHours() + ':' +
(d.getMinutes() < 10 ? '0' : '') + d.getMinutes()
);
- 您可以测试在浏览器中&的node.js控制台。
或者,在你的语法,我想:
javascript{
d = new Date(),
(d.getHours() < 10 ? '0' : '') + d.getHours() + ':' +
(d.getMinutes() < 10 ? '0' : '') + d.getMinutes()
}
请看下面使用的通用格式工具
today = new Date();
var dateString = today.format("dd:mm");
alert(dateString);
有关详细信息和的jsfiddle一个干净的解决方案,敬请期待here
我不认为Date.prototype.format()存在http://screencast.com/t/6hO9NZVSaRc请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/日期/原型 – 2014-09-04 13:25:34
你是对的伊凡,你必须添加在jsFiddle中引用的原型。我必须承认,如果它只是一个格式化操作,你的解决方案更轻,更好。但如果你需要更多的日期操纵,原型更广泛。 – 2014-09-04 13:39:40
谢谢你,正如我所需要的! – 2014-09-04 20:32:11