CSS3 + Javascript电子时钟js特效

此博客展示了如何使用JavaScript实时获取并显示当前日期、小时、分钟和秒,通过setInterval函数实现动态刷新。

下载地址

// Create two variable with the names of the months and days in an arrayvar monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]// Create a newDate() objectvar newDate = new Date();// Extract the current date from Date objectnewDate.setDate(newDate.getDate());// Output the day, date, month and year $("#Date").html(dayNames[newDate.getDay()] + " " + newDate.getDate() + " " + monthNames[newDate.getMonth()] + " " + newDate.getFullYear());setInterval( function() { // Create a newDate() object and extract the seconds of the current time on the visitor"s var seconds = new Date().getSeconds(); // Add a leading zero to seconds value $("#sec").html(( seconds < 10 ? "0" : "" ) + seconds); },1000); setInterval( function() { // Create a newDate() object and extract the minutes of the current time on the visitor"s var minutes = new Date().getMinutes(); // Add a leading zero to the minutes value $("#min").html(( minutes < 10 ? "0" : "" ) + minutes); },1000); setInterval( function() { // Create a newDate() object and extract the hours of the current time on the visitor"s var hours = new Date().getHours(); // Add a leading zero to the hours value $("#hours").html(( hours < 10 ? "0" : "" ) + hours); }, 1000);

424_5e49a7d5b65411ceb6bc4a03d9dfa745.png

dd:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值