Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display future date with moment.js

I'm trying to use http://momentjs.com/docs/#/manipulating/ to show the day (Monday), the month (July) and the number date (20) four days in the future. so basically I'm trying to do today+4 and to display day, month, #. i knew jquery was the best bet when i came upon moment.js

i put the

<script src="js/moment.js"></script>
<script>
    moment().format();
</script>

in my footer like the instructions said and I'm using

<p class="day"><script>document.write(moment().add(4, 'day'));</script></p>

to try and display it. this part is just for the "Friday" part cause I'm still trying to figure out how to do the month and number date, but I'm thinking help with this part may really help with the other two.

Your help is greatly appreciated. Thank you.

like image 805
Felicyia Avatar asked Oct 27 '25 05:10

Felicyia


2 Answers

var fourDaysForward = new moment().add(4, 'day');
document.write(fourDaysForward.format('dddd MMMM DD')); 
like image 106
Tholle Avatar answered Oct 30 '25 05:10

Tholle


Use the .format() with the appropriate arguments. See docs here

Thus, I think you're looking for moment.format('dddd MMMM D')

like image 32
ded Avatar answered Oct 30 '25 04:10

ded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!