简体   繁体   English

比较每个li给出的时间与当前时间

[英]Compare time give in each li with Current Time

What is this about ? 这是什么意思?

I am trying to check if the current time is less then or equal to the time given in particular span 我正在尝试检查当前时间是否小于或等于特定跨度中给定的时间


What's the issue ? 有什么问题?

I want to set timer for each li without page refresh to check if the time is equal to current time or time given in span is less then 2 second comparing with the current time. 我想为每个li设置计时器而无需刷新页面,以检查时间是否等于当前时间或span中给定的时间与当前时间相比是否小于2秒。 I am not sure what's the good practise to check this for individual li ? 我不确定对李某个人进行检查是否有什么好的做法?


Html HTML

<ul>
    <li>
        <span class="hidden time">December 3 2015 21:58:00 UTC-0800</span>
    </li>
    <li>
        <span class="hidden time">December 12 2015 15:00:00 UTC-0800</span>
    </li>
</ul>

One counter would do just fine. 一个柜台就可以了。 You would want to set the interval to something less than 2 seconds and at each interval use the jQuery .filter() method to see if there're any spans with a time meeting the condition and then add the class. 您可能希望将时间间隔设置为小于2秒,并在每个时间间隔使用jQuery .filter()方法来查看是否存在满足条件的时间跨度,然后添加类。

 $(function() { var timer = setInterval(function() { var ts = Date.now(); $('.current').text( new Date(ts) ); $('ul > li > .hidden.time').filter(function() { var thisTime = new Date( $(this).text().trim() ); return thisTime - ts <= 2000; }) .addClass('active'); }, 1000); }); 
 .active { background: black; color: yellow; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div> Current Time: <span class="current"></span> </div> <ul> <li> <span class="hidden time">December 3 2015 21:58:00 UTC-0800</span> </li> <li> <span class="hidden time">December 12 2015 15:00:00 UTC-0800</span> </li> </ul> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM