ok, I am writing a small piece of code to get the ISO date format value for yesterday.
the code:
var dateString = new Date(); var yesterday = dateString.getFullYear(); yesterday += "-"+dateString.getMonth()+1; yesterday += "-"+dateString.getDate()-1;
The above code outputs 2009-111-23. This does not explicitly apply to dateString.getMonth () as an intiger, and binds 1 to the end.
Does "-" + put getDate () in a string before dateString.getDate ()?
this leads to the desired result.
var dateString = new Date(); var yesterday = dateString.getFullYear() + "-"; yesterday += dateString.getMonth()+1+ "-"; yesterday += dateString.getDate()-1;
Although I donβt really like the way it looks ... no matter what happens.
Can someone explain to me why javascript works like this? are there any explanations why this is happening?
source share