-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] 第49天 写个还剩下多少天过年的倒计时 #187
Labels
js
JavaScript
Comments
const day = Math.floor((new Date('2019-12-31 23:59:59:999') - new Date()) / 864e5) // 210 |
西历新年好算,顺带增加了小时、周、月的维度。农历就懵了……等大佬答案 const countDown = (range = "day") => {
const nowDate = new Date();
const currentYear = nowDate.getFullYear();
const nextYear = new Date(currentYear + 1, 1, 1);
const rangeBase = {
minute: 1000 * 60,
hour: 1000 * 60 * 60,
day: 1000 * 60 * 60 * 24,
week: 1000 * 60 * 60 * 24 * 7,
month: 1000 * 60 * 60 * 24 * 30
};
return Math.floor(
(nextYear.valueOf() - nowDate.valueOf()) /
(rangeBase[range] || rangeBase.day)
);
};
console.log(countDown("hour"));
console.log(countDown());
console.log(countDown("week"));
console.log(countDown("month")); |
|
Math.floor((new Date("2019-12-31") - Date.now()) / (10**5 *36*24)) |
我也想知道算阴历的话应该怎么算 |
抬个杠, |
console.log(Math.floor((new Date('2022-12-31 23:59:59:999') - new Date()) / 86400000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第49天 写个还剩下多少天过年的倒计时
The text was updated successfully, but these errors were encountered: