|
°²×¿×¨ÓÃÍÂ˾toastµ¹¼ÆÊ±µ½Ö¸¶¨Ê±¼ä²¢ÏÔʾʣÓàʱ¼ä
- /**
- *🍎½»Á÷ QQ Ⱥ 711841924 Ⱥһ£¬Æ»¹ûÄÚ²âȺ£¬528816639
- * µ¹¼ÆÊ±µ½Ö¸¶¨Ê±¼ä²¢ÏÔʾʣÓàʱ¼ä£¨ºìÉ«ÎÄ×Ö£©
- * @param {string} targetTime - Ä¿±êʱ¼ä£¬¸ñʽΪ 'HH:mm:ss'
- * ÊÊÓñ¾ÎĵµES5ϵͳ°²×¿ JavaScriptÒýÇæRhino
- */
- function countdownToTime(targetTime) {
- // ÉèÖÃÎÄ×ÖÑÕɫΪºìÉ«
- toast.setTextColor("#FF0000");
-
- // ÉèÖÃ͸Ã÷¶È (¿ÉÑ¡)
- toast.setAlpha(230);
-
- // ÉèÖÃ×ֺŠ(¿ÉÑ¡)
- toast.setSize(16);
-
- // ½âÎöÄ¿±êʱ¼ä
- var now = new Date();
- var target = new Date();
-
- var timeParts = targetTime.split(':');
- var hours = parseInt(timeParts[0]);
- var minutes = parseInt(timeParts[1]);
- var seconds = parseInt(timeParts[2]) || 0;
-
- target.setHours(hours, minutes, seconds, 0);
-
- // Èç¹ûÄ¿±êʱ¼äÒѹý£¬ÔòÍÆ³Ùµ½Ã÷Ìì
- if (target <= now) {
- target.setDate(target.getDate() + 1);
- }
-
- // ¼ÆËã³õʼʣÓàʱ¼ä£¨Ã룩
- var remainingSeconds = Math.floor((target - now) / 1000);
-
- // Á¢¼´ÏÔʾһ´Îµ¹¼ÆÊ±
- showCountdown(remainingSeconds);
-
- // ÿÃë¸üÐÂÒ»´Îµ¹¼ÆÊ±
- var interval = setInterval(function() {
- remainingSeconds--;
- showCountdown(remainingSeconds);
-
- if (remainingSeconds <= 0) {
- clearInterval(interval);
- // ʱ¼äµ½ÁË
- toast.show("ʱ¼äµ½ÁË£¬¿ªÊ¼Ö´ÐÐÈÎÎñ£¡");
- }
- }, 1000);
-
- return interval;
- }
- /**
- * ÏÔʾµ¹¼ÆÊ±ÐÅÏ¢£¨ºìÉ«ÎÄ×Ö£©
- * @param {number} totalSeconds - Ê£Óà×ÜÃëÊý
- */
- function showCountdown(totalSeconds) {
- // È·±£ÎÄ×ÖÑÕÉ«ÊǺìÉ«
- toast.setTextColor("#FF0000");
-
- if (totalSeconds <= 0) {
- toast.show("ʱ¼äµ½ÁË£¬¿ªÊ¼Ö´ÐÐÈÎÎñ£¡");
- return;
- }
-
- var hours = Math.floor(totalSeconds / 3600);
- var minutes = Math.floor((totalSeconds % 3600) / 60);
- var seconds = totalSeconds % 60;
-
- var message = "¾àÀëÖ´Ðл¹Ê£: ";
- if (hours > 0) {
- message += hours + "Сʱ ";
- }
- if (minutes > 0) {
- message += minutes + "·ÖÖÓ ";
- }
- message += seconds + "Ãë";
-
- toast.show(message);
- }
- // ʹÓÃʾÀý
- countdownToTime('18:50:00');
¸´ÖÆ´úÂë
|
|