How to Set Flask Server Timezone to Gmt

We have our flask server up and running. However requirement has come up to set server timzone as GMT instead of UTC. I could not find anything related to timezone in flask documentation. Is this possible? I know it is possible in django.

2 Answers

you can make use of the python datetime.now() instead of the datetime.utcnow(), or you can create a function that will automatically do the timezone conversions on all date objects for you on the sever.

I hope that will help you

0

This is another option in flask

from datetime import datetime

import pytz

UTC = pytz.utc

IST = pytz.timezone('Asia/Kolkata')
  
datetime_ist = datetime.now(IST)
print(datetime_ist.strftime('%Y-%m-%d %H:%M:%S'))
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest