admin管理员组文章数量:1321447
In one of the App I am getting date as following formate. Mon Aug 18 23:59:59 IST 2014 Below is ng-repeat for angular js
Offer ends: {{msg.endTime}}
Which render as app receive date in this format. Offer ends: Mon Aug 18 23:59:59 IST 2014
I want to show remaining time instead of Date/Time. Like Offers ends in 2days 40 minutes 10 seconds
Which is simple way to achieve with and without worry about TIMEZone
I am planning to use momentjs with format moment().format("ddd MMM HH:mm:SS")
Demo app /
In one of the App I am getting date as following formate. Mon Aug 18 23:59:59 IST 2014 Below is ng-repeat for angular js
Offer ends: {{msg.endTime}}
Which render as app receive date in this format. Offer ends: Mon Aug 18 23:59:59 IST 2014
I want to show remaining time instead of Date/Time. Like Offers ends in 2days 40 minutes 10 seconds
Which is simple way to achieve with and without worry about TIMEZone
I am planning to use momentjs with format moment().format("ddd MMM HH:mm:SS")
Demo app https://flipkartoffers.firebaseapp./
Share Improve this question edited Aug 26, 2014 at 3:13 Kato 40.6k6 gold badges122 silver badges149 bronze badges asked Aug 25, 2014 at 19:38 Wasim ShaikhWasim Shaikh 7,04018 gold badges62 silver badges88 bronze badges 2- You should try moment's calendar() method, which automagically does the "in 2 days" and so on. – Kato Commented Aug 26, 2014 at 3:12
- Have you checked the answers we provided? If one of them fits, please accept it or share your own solution if you found one. Thanks in advance. – apairet Commented Aug 28, 2014 at 15:31
3 Answers
Reset to default 5you can create your own filter for that pourpose ...
yourOwnApp.filter('datetimeToNow', function() {
return function(input) {
if(!input) return;
return moment(input).fromNow();
};
});
... subsequently just call it from within your ngRepeat:
Offer ends: {{msg.endTime | datetimeToNow}}
Cheers, Luca
It is very easy to achieve using moment and angular-moment. You can use the am-time-ago
directive. https://github./urish/angular-moment
<span am-time-ago="message.time"></span>
<span am-time-ago="message.time" am-preprocess="unix"></span>
am-time-ago
works for both 'negative' time (past) and 'positive' time (future)
I fixed using Luca's answer , and changed formate of the date as below. Removed the IST Mon Aug 18 23:59:59 2014
<span>Ends {{msg.endTime | formatTime}}</span>
-
myApp.filter('formatTime', function() {
return function(text) {
var m = moment(text , 'ddd MMM DD HH:mm:ss YYYY');
return m.fromNow();
}
})
本文标签: javascriptConvert date to remaining time using momentjsStack Overflow
版权声明:本文标题:javascript - Convert date to remaining time using momentjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742100305a2420771.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论