的JavaScript等价的PHP mktime
荫的使用mktime在PHP()函数来获取给定的年,月,日的秒和分像的JavaScript等价的PHP mktime
$seconds = mktime($hour,$minute,$month,$day,$year);
,但我想用同样的JavaScript ...任何人都可以建议我在JavaScript中使用其等价函数的方式,它采用高于所有参数并返回秒数...我搜索了很多源,但没有人给我输出。
var seconds = new Date(year, month, day, hours, minutes, seconds, 0).getTime()/1000;
以上将自1-1-1970年以来的秒数。 getTime()
给出毫秒因此devide 1000。请注意(如阿拉尔关闭也提到),当月范围从0-11,所以你可能需要更正,相比mktime
function java_mktime(hour,minute,month,day,year) {
return new Date(year, month - 1, day, hour, minutes 0, 0).getTime()/1000;
}
优秀@Bart ....你做到了这一点... – Gautam3164 2013-02-25 08:43:29
可以使用Date对象(月是从0到11的值):
var date = new Date(year, month, day, hours, minutes, seconds);
使用日期对象
function mktime(hour,minute,month,day,year){
a=new Date()
a.setHours(hour)
a.setMinutes(minute)
a.setDate(day)
a.setYear(year)
return a.getTime()/1000
}
或者,
function mktime(hour,minute,month,day,year){
return (new Date(year, month, day, hour, minute, 0)).getTime()/1000;
}
getTime返回毫秒而不是秒,您可以每1000分钟 – Tobia 2013-02-25 07:54:36
@Tobia:是的,错过了。谢谢:) – Manishearth 2013-02-25 07:55:14
http://phpjs.org/functions/mktime/ – dfsq 2013-02-25 07:51:40