我有一个competition
-module,当我发布比赛时,比赛结束还有一个截止日期。我的API JSON返回结束日期。我想使用MomentJS
插件,到目前为止,我仅添加了:
<script src="/js/moment.min.js"></script>
和我的HTML:
<time class="newstime" datetime="2014-08-04T10:00:00.000Z">//DISPLAY REMAINING TIME HERE</time>
如何实现显示剩余时间?
提前致谢
最佳答案
有一个名为Moment-countdown的插件。可以使用bitbucket进行本地化
这是git hub的一段代码
//from then until now
moment("1982-5-25").countdown().toString(); //=> '30 years, 10 months, 14 days, 1 hour, 8 minutes, and 14 seconds'
//accepts a moment, JS Date, or anything parsable by the Date constructor
moment("1955-8-21").countdown("1982-5-25").toString(); //=> '26 years, 9 months, and 4 days'
//also works with the args flipped, like diff()
moment("1982-5-25").countdown("1955-8-21").toString(); //=> '26 years, 9 months, and 4 days'
//accepts all of countdown's options
moment().countdown("1982-5-25", countdown.MONTHS|countdown.WEEKS, NaN, 2).toString(); //=> '370 months
关于javascript - MomentJS-如何显示剩余时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24381779/