javascript date adding days getting wrong days [duplicate]

439
May 30, 2017, at 04:10 AM

This question already has an answer here:

  • Add days to JavaScript Date 30 answers

I am using this code on the page to show when the next few dates are, they are always the next few days... but it is not working now:

<script>var now = new Date();
    var day = ("0" + (now.getDate()+3)).slice(-2);
    var day2 = ("0" + (now.getDate()+4)).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var today = (month)+"/"+(day)+"/"+now.getFullYear();
    var today2 = (month)+"/"+(day2)+"/"+now.getFullYear();
    document.write(today); document.write(' and/or ');document.write(today2);
</script>

But it is putting this out:

currently scheduled for: 05/32/2017 and/or 05/33/2017

how do I get the + 1 to have it go to the next month if it needs to?

Answer 1

Try this

 <script>
var now = new Date();
    var day = ("0" + (now.setDate(now.getDate()+3)).getDate()).slice(-2);
    var day2 = ("0" + (now.setDate(now.getDate()+4)).getDate()).slice(-2);
    var month = ("0" + (now.setMonth(now.getMonth() + 1+1)).getMonth()).slice(-2);
    var today = (month)+"/"+(day)+"/"+now.getFullYear();
    var today2 = (month)+"/"+(day2)+"/"+now.getFullYear();
    document.write(today); document.write(' and/or ');document.write(today2);
</script>
Rent Charter Buses Company
READ ALSO
Customizing the points on a polygon edge in Google Maps

Customizing the points on a polygon edge in Google Maps

When creating an editable polygon in Google Maps there are added a slightly opacid points to each edge, which enables adding new points to the polygonI am looking to customize these points, so they only appear after creation and possible style them as well

352
ImmutableJS: Return unchanged List after push

ImmutableJS: Return unchanged List after push

With ImmutableJS is there a way to push an "empty" value onto a List, returning the same unchanged List? For example, if I have a List xs and an Option a, I'd like to do something like:

355
JS - Testing code that uses an IntersectionObserver

JS - Testing code that uses an IntersectionObserver

I have a (rather poorly written) javascript component in my application that handles infinite scroll pagination, and i'm trying to rewrite it to use the IntersectionObserver, as described here, however i'm having issues in testing it

318