"I tested the code with my browser. It works correctly. "
"It also works when testing with JSFiddle. "
When testing the code with your browser, with or without JSFiddle, what you get is the local time/date of your PC.
When you copy the code to BrainShop, it runs at the server side. What you gets the server time, which time zone is UTC. You need to covert the time or date to your local time zone. For example, if your time zone is E8, you should add 8 to the server hour.