如何才能在JavaScript中获得当前时间 [英] How do I get the current time only in JavaScript
本文介绍了如何才能在JavaScript中获得当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过 var x = date()
并得到:
星期二2012年5月15日05:45:40 GMT-0500
但是我只需要当前时间,例如05:45
如何将其分配给变量?
解决方案
var d = new Date(2011-04-20T09:30:51.01 );
d.getHours(); // => 9
d.getMinutes(); // => 30
d.getSeconds(); // => 51
或
code> var d = new Date(); //现在
d.getHours(); // => 9
d.getMinutes(); // => 30
d.getSeconds(); // => 51
How can I get the current time in JavaScript and use it in a timepicker?
I tried var x = date()
and got:
Tue May 15 2012 05:45:40 GMT-0500
But I need only current time, like 05:45
How can I assign this to a variable?
解决方案
var d = new Date("2011-04-20T09:30:51.01");
d.getHours(); // => 9
d.getMinutes(); // => 30
d.getSeconds(); // => 51
or
var d = new Date(); // for now
d.getHours(); // => 9
d.getMinutes(); // => 30
d.getSeconds(); // => 51
这篇关于如何才能在JavaScript中获得当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文