Closed 2jfw closed 7 hours ago
I remember seeing this effect for the first time and puzzling over it ... but what you're forgetting is this part:
var date : Date = new Date();
This will set the date to the machine's current date/time. So, this value is the 31st July.
Then:
date.month = 5; // June (!)
will change the month to June. So, the date is now, 31st June. BUT that date doesn't exist, so the Date object internally will actually be 1st July. So then:
date.date = 26;
means the date value goes to 26, so we're now at 26th July.
Next time, when you set the month back to June, 26th June is still valid so it works...
So to avoid this, make sure you change the date value before the month value!
var date : Date = new Date();
date.date = 26;
date.month = 5; // June (!)
date.fullYear = 2024;
trace(date);
Well, not so magical after all ... 🤨 Thanks for bringing this to attention and the insight on this, Andrew!
I have encountered a very strange behavior of the
Date
object, when the local machine/PC date (Windows 10, Version @10.0.19045 Build 19045, AIR 50.2.4) is set to 31.07.2024 and the date object then has its date changed: It will state a wrong month (behind the scenes: setting month is ignored)It's easier to show sample code:
Run this code without changing your local machine's date:
You will see the following correct output: [Of course hh:mm:ss will be different when you run the code]
Now change your local machine's date to 31.07.2024 and run the code again. You will see:
As you see, the initial trace of the date incorrectly states "July" (
6
) instead of "June" (5
). In the debugger, you can see that initially assigning the month5
will keep the date object's month on6
. Only second time it will become5
.[Tooltip from IDE]
This only happens when your local machine's date was set to 31.07. Changing the year does not affect the incorrect output.
🧙💬 So, what is the "magic" behind the date 31.07 ? It seems like a really "strange" issue to me...