Iam using mktime() function in php to get the seconds for given year,month,date and minutes as like
$seconds = mktime($hour,$minute,$month,$day,$year);
but I want to use the same in javascript...can anyone suggest me the way to use its equivalent function in javascript that takes above all parameters and returns number of seconds...I have searched so many sources but no one has given me the output.
var seconds = new Date(year, month, day, hours, minutes, seconds, 0).getTime() / 1000;
The above will give seconds since 1-1-1970. getTime()
gives miliseconds therefore devide by 1000. Note (as Aler Close also mentioned), the month ranges from 0-11, so you might need to correct that compared to mktime
function java_mktime(hour,minute,month,day,year) {
return new Date(year, month - 1, day, hour, minutes 0, 0).getTime() / 1000;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With