2012-07-12 66 views

回答

18

您加起來位:

var dt = new Date(); 
var secs = dt.getSeconds() + (60 * dt.getMinutes()) + (60 * 60 * dt.getHours()); 

或者如果你喜歡

var dt = new Date(); 
var secs = dt.getSeconds() + (60 * (dt.getMinutes() + (60 * dt.getHours()))); 
+0

如果您打算將它存儲在某處,請考慮使用'getUTCHours'和'getUTCMinutes' – 2017-01-20 07:26:02

2

例如(in action):

​var today = new Date(), today_abs = new Date(), today_secs = 0; 
today_abs.setHours(0); 
today_abs.setMinutes(0); 
today_abs.setSeconds(0); 
today_secs = (today.getTime() - today_abs.getTime())/1000;​ 
相關問題