I am working on a project that requires this kind of text response on a date object.
"1 day 7 hours away" --- it needs to be this way - not "31 hours away" or "1 day away" -- also I am using moment js - as I am doing language switching between English and German - so I've tapped into the moment.js language locale
moment.locale('de')
I am using moment js - currently I've created a fake date object
var futureDate = new Date()
futureDate.setDate(futureDate.getDate() + 1)// add a day
futureDate.setHours(7)// add 7 hours
when I try and render the moment js
moment(futureDate).endOf('day').fromNow()
it just says "in a day"
How do I modify the moment function to handle 1 day 7 hours -- and maybe re-jig the sentence?
--- code snippet attempt
moment.locale('de') // switch between en and de -- english and german
var futureDate = new Date()
futureDate.setDate(futureDate.getDate() + 1)// add a day
futureDate.setHours(7)// add 4 hours
// Results in hours
console.log(moment(futureDate).endOf('day').fromNow());
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
code test 2 using difference
moment.locale('de') // switch between en and de -- english and german
var a = moment();
var b = moment(a).add(31, 'hours');
// Results in days
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>