网页制作16-Javascipt时间特效の设置D-DAY倒计时

01、效果图

02、应用

new Date()//返回今天日期

new Date("April 1,2025")//返回目标日期

document.write()//文档显示

getTime()返回当日毫秒数

Math.floor(amadays / (1000 * 60 * 60 * 24)//把毫秒换算天

03、代码

html 复制代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
 <script> 
  var aim= new Date("April 1,2025"); 
  var aimday="愚人节"; 
  var today = new Date(); 
  var amadays = aim.getTime() - today.getTime(); 
  var remain = Math.floor(amadays / (1000 * 60 * 60 * 24)); //把毫秒换算天
  if (remain >= 0) ;
document.write("现在离2025年"+aimday+"还有: <font color=red><b>"+remain +"</b></font>天"+"<br>");
	 
	 document.write(aim+"<br>");//返回目标日期
	 document.write(today+"<br>");//返回今天日期
	  document.write( aim.getTime()+"<br>");//返回目标日期毫秒数
	 document.write(today.getTime()+"<br>");//返回当日毫秒树木数 document.write(amadays+"<br>");
	document.write(remain+"<br>");//返回今日与目标日的差值
</script>
<body>
</body>
</html>
相关推荐
转转技术团队4 分钟前
验证码识别实战:前端不写页面,改训模型了?
前端
MomentYY8 分钟前
Temperature:AI 的“脑洞旋钮”
前端·llm·ai编程
远航_29 分钟前
OpenSpec 完整详细介绍
前端·后端
召钱熏39 分钟前
状态枚举正确≠渲染正确:一个语音按钮的状态机边界修复实录
android·前端
SkyWalking中文站41 分钟前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
cidy_9841 分钟前
Dify 操作教程:工作流编排 & Chat 对话编排
前端·工作流引擎
tangdou36909865543 分钟前
AI真好玩系列-2分钟快速了解DeepAgents | Quick Guide to DeepAgents in 2 Minutes
前端·javascript·后端
张元清44 分钟前
React useIntersectionObserver Hook:懒加载与可见性检测(2026)
javascript·react.js
小四的小六1 小时前
AI Agent效果评测实战——搭完Agent才是噩梦的开始
前端
梨子同志1 小时前
JavaScript
前端