qjuery 动态倒计时

 前台代码: 

<div class="yomibox" style='float: left;' data="<%#Convert.ToDateTime(Eval("end_time")).ToString("yyyy-MM-dd HH:mm:ss") %>"></div>    

<script type="text/javascript">

        /** 
    * 倒计时插件
    */
        var a = <%=DTcms.Common.SiteHelper.GetTimeLikeJS()%>;
        var arr = [a, a, a, a, a];
        (function ($) {
            $.fn.yomi = function (i) {
                var data = "";
                var _DOM = null;
                var TIMER;
                createdom = function (dom) {
                    _DOM = dom;
                    data = $(dom).attr("data");
                    data = data.replace(/-/g, "/");
                    data = Math.round((new Date(data)).getTime() / 1000);


                    $(_DOM).append("<ul class='yomi'><li class='yomiday'></li><li class='split'>天</li><li class='yomihour'></li><li class='split'>时</li><li class='yomimin'></li><li class='split'>分</li><li class='yomisec'></li><li class='split'>秒</li></ul>")
                    reflash();


                };
                reflash = function () {
                    arr[i] = arr[i] + 1000;
                    if((data - Math.round(arr[i] / 1000))<=0){
                        //$(_DOM).find(".yomi").html("<li><%=SiteHelper.GetHouseStatus(4) %></li>");
                        $(_DOM).find(".yomi").html("<li>已结束</li>");
                    }
                    var range = data - Math.round(arr[i] / 1000),
                                secday = 86400, sechour = 3600,
                                days = parseInt(range / secday),
                                hours = parseInt((range % secday) / sechour),
                                min = parseInt(((range % secday) % sechour) / 60),
                                sec = ((range % secday) % sechour) % 60;
                    $(_DOM).find(".yomiday").html(nol(days));
                    $(_DOM).find(".yomihour").html(nol(hours));
                    $(_DOM).find(".yomimin").html(nol(min));
                    $(_DOM).find(".yomisec").html(nol(sec));


                };
                TIMER = setInterval(reflash, 1000);
                nol = function (h) {
                    //return h > 9 ? h : '0' + h;
                    return h;
                }
                return this.each(function () {
                    var $box = $(this);
                    createdom($box);
                });
            }
        })(jQuery);
        $(function () {
            $(".yomibox").each(function (i) {
                $(this).yomi(i);
            });
            $("head").append("<style type='text/css'>.yomi {list-style:none;}.yomi li{float:left;color:#9b9b9b;width:auto;height:auto;margin:0;border-radius:0;border:0;}.yomi li.split{color:#9b9b9b;}</style>")
        });

    </script>


后台代码:       

//获取时间tick
        public static long GetTimeLikeJS()
        {
            long lLeft = 621355968000000000;


            DateTime dt = DateTime.Now;


            long Sticks = (dt.Ticks - lLeft) / 10000;


            return Sticks;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Java GUI中动态显示倒计时,您可以使用Swing或JavaFX库,并在单独的线程中更新倒计时。下面是一个使用Swing的示例,演示如何在GUI中显示动态倒计时: ```java import javax.swing.*; import java.awt.*; import java.text.SimpleDateFormat; import java.util.Date; public class DynamicCountdownGUIExample { public static void main(String[] args) { JFrame frame = new JFrame("Dynamic Countdown GUI Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a label to display the countdown JLabel countdownLabel = new JLabel(); countdownLabel.setFont(new Font("Arial", Font.BOLD, 48)); frame.add(countdownLabel); // Calculate the end time of the countdown (10 seconds from now) Date endTime = new Date(System.currentTimeMillis() + 10000); // Update the countdown every second new Thread(() -> { while (true) { // Calculate the remaining time long remainingTime = endTime.getTime() - System.currentTimeMillis(); if (remainingTime <= 0) { countdownLabel.setText("Time's up!"); break; } // Format the remaining time as "mm:ss" SimpleDateFormat format = new SimpleDateFormat("mm:ss"); String formattedTime = format.format(new Date(remainingTime)); countdownLabel.setText(formattedTime); // Wait for one second try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }).start(); // Set the size of the frame and show it frame.setSize(400, 200); frame.setVisible(true); } } ``` 在此示例中,我们创建了一个JFrame并向其中添加一个JLabel。我们计算倒计时的结束时间,并使用一个单独的线程来更新倒计时。我们使用SimpleDateFormat格式化倒计时,并将其显示在JLabel中。如果倒计时结束,我们将在JLabel中显示"Time's up!"。使用Thread.sleep方法使线程等待一秒钟,然后再更新倒计时。这样,我们就可以创建一个动态倒计时GUI了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值