How to check which timezone the app will run in azure

Viewed 2783

I have a python web app which extracts few files from the webserver. Files are named as per date, so it looks like

transData2018/09/13.csv

These files are uploaded by someone whose timezone is GMT-4. My timezone is GMT+8. As of now, I am running the python app locally so the app is ahead. Now because it is ahead of date time, the code has to look for the files of previous day. So considering if today's date is 15-Sept, code has to look for files with date 14-Sept. This all setup works fine locally.

Now my plan is to deploy this python app on azure web app platform. Once deployed, I do not know which timezone it will work in and what time it will pick. Based on that, should the code look for the previous date in the files or just the todays date.

In the code I am doing:

previous_date = str(datetime.now().date() - timedelta(days=1))

to get the previous date value but this will probably fail in scenario:

  1. If they uploaded the file on 15th-Sept so the files will have name transData2018/09/15.csv, but the code will look for the file transData2018/09/14.csv which is not correct.

How should I deal with this situation? Thanks

1 Answers

The default server time set on the Azure Website platform is UTC. Using the code segments in the following article, you can find out which time zones are supported on the platform and easily convert the UTC to that time zone. Refer Get the local server time for your Azure Website.

You could make an addition to the Web Apps APP SETTINGS to set the Web App to local time and add the TimeZoneInfo Id value to the WEBSITE_TIME_ZONE attribute, then, the DateTime.Now() method will return local time instead of the default time.

Refer Changing the server time zone on Azure Web Apps and Set the time zone for more details.

Related