728x90
function getLastDayOfMonth(year, month) {
const months = [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'
];
const date = new Date(year, month + 1, 0);
return `Last day of ${months[month]}, ${year} is ${date.getDate()}`;
}
console.log( getLastDayOfMonth(2012, 0) ); // 31
console.log( getLastDayOfMonth(2012, 1) ); // 29
console.log( getLastDayOfMonth(2013, 1) ); // 28
728x90
function getSecondsTodayVerOne() {
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const diff = now - today;
return Math.round(diff / 1000);
}
function getSecondsTodayVerTwo() {
const now = new Date();
return now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
}
console.log( getSecondsTodayVerOne() );
console.log( getSecondsTodayVerTwo() );

+ Recent posts