0

thanks for taking the time to read my question.

At a high level I have a project that receives a file every day whose name ends in a date formatted yyyymmdd (file_20211118.xml would be today's file). The project reads data from the file and displays it on the web.

So the project only updates on the next day and after it receives a new file I have some javascript that looks like this

var todaysDateyyyymmdd = new Date().toISOString().slice(0,10).replace(/-/g,"");

xhttp.open("GET", "file_" + todaysDateyyyymmdd + ".xml", true);

I am in the EST time zone. The process works great for me until 7:00PM EST when everything disappears from the web. I am assuming it is because todaysDateyyyymmdd no longer equals the date on the file (maybe even specific to my browser time). I just can't figure out what to do to extend todaysDateyyyymmdd +5:00.

Any ideas would be greatly appreciated.

Gazrok
  • 99
  • 2
  • 8
  • Your problem is toISOString returns the UTC date, not local so it will be wrong for the period of ± the local offset from midnight. See [*Need better way to format Date as yyyymmdd without jquery or additional library*](https://stackoverflow.com/questions/30216166/javascript-only-need-better-way-to-format-date-as-yyyymmdd-without-jquery-or-a). – RobG Nov 19 '21 at 02:25
  • I don't see anything in the associated question about time zones, just adding date parts. Can you be more specific in telling me what I should be looking at here? – Gazrok Nov 19 '21 at 13:24
  • You are using *toISOString* to format a Date as YYYYMMDD. That returns UTC values, not local. The duplicate shows how to get YYYYMMDD as local, not UTC. – RobG Nov 19 '21 at 21:37

0 Answers0