I am working on a project that requires such a textual response to a date object.
"1 day 7 hours" --- It should be like this - not "31 hours" or "1 day", - In addition, I use the js moment - since I am switching languages ββbetween English and German - so I applied the language moment.js
moment.locale('de')
I am using js moment - I have currently created a fake date object
var futureDate = new Date()
futureDate.setDate(futureDate.getDate() + 1)
futureDate.setHours(7)
when i try to render moment js
moment(futureDate).endOf('day').fromNow()
he just says "every other day"
How to change the moment function for processing 1 day 7 hours - and perhaps repeat the sentence?
--- code snippet attempt
moment.locale('de')
var futureDate = new Date()
futureDate.setDate(futureDate.getDate() + 1)
futureDate.setHours(7)
console.log(moment(futureDate).endOf('day').fromNow());
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
Run codeHide resultchecking code 2 using difference
moment.locale('de')
var a = moment();
var b = moment(a).add(31, 'hours');
console.log(b.diff(a, 'days'));
console.log(b.diff(a, 'days', true));
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
Run codeHide result