1

I recently deployed my flask application to AWS Elastic Beanstalk. Everything seemed fine until I realized that datetime.datetime.now() is returning UTC time(7 hours ahead of local time for me) rather than local time. It doesn't do this when I run it on localhost. What would the issue be and what would be the steps I should take to mitigate this problem? Thanks.

Parth Patel
  • 135
  • 1
  • 4
  • 12

1 Answers1

1

It is a common practice to configure servers in UTC. So it is normal that datetime.datetime.now() gives you UTC time.

You can use the pytz library to manage time zones in your code, to transition dates to your local timezone when needed.

It is really useful to read this guide about date and timezones best practices to have a broader view about how to manage the interaction between your server's time and your local timezone.

Jundiaius
  • 6,214
  • 3
  • 30
  • 43