javascript - Add time to date with angular -
in firebase have:
firebase generated date created day. terms set user when above generated.
so example have:
1439612582756 // formats to: aug 14, 2015 15 // formats to: "net 15" in code
my code looks this:
<td>{{invoice.settings.created | date}}</td> <td>{{invoice.settings.created + invoice.settings.terms | date}}</td>
i have installed moment.js
, 'angular-moment.js' able format , play dates, didn't see way add time date. for-each don't want have pre-scripting this. maybe custom filter add terms date?
obviously, code above not function. made demonstrate wanting.
any appreciated!
update
using page: http://momentjs.com/docs/#/durations/add/
came filter:
.filter('dateterms', function() { return function(created, terms) { var = moment.duration(created, 'd'); var b = moment.duration(terms, 'd'); return a.add(b).days(); } })
but when call it, end 0
?
<td>{{invoice.settings.created | date}}</td> <td>{{invoice.settings.terms | dateterms}}</td> // line
i'm guessing it's because i'm passing filter terms , not created date. how pass 2 variables? think i'm getting closer....
update 2
i dumped moments crap. have now:
.filter('dateterms', function() { return function(input, created) { var date = new date(created*1000); date.setdate(date.getdate() + input); return (date.getmonth()+1)+'/'+ date.getdate() +'/'+date.getfullyear(); } })
and in html:
<td>{{invoice.settings.terms | dateterms:1439746291480}}</td> 1439746291480 converts `aug 16, 2015`
this results in:
8/24/47601
using method chaining moment.js, can perform these kind of calculations in single statement. example:
return moment(new date(created)).add(terms, 'days').format('mm/dd/yyyy');
using moment.js make life easier in other ways, since automatically deals daylight savings, leap years, time zones, etc., making of date , time calculations more accurate.
Comments
Post a Comment