I recommend you reading this https://docs.djangoproject.com/en/4.2/topics/i18n/timezones/.
On Wednesday, August 16, 2023 at 12:46:53 PM UTC-5 Madhusudhan Reddy wrote: > But I am using only fast api for APIs > > On Wed, 16 Aug 2023 at 3:45 PM, Ruby <[email protected]> wrote: > >> You seem to be reinventing the wheel, Django already has timezone support >> when you set USE_TZ >> <https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-USE_TZ> to >> True, >> Note that your TIME_ZONE >> <https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-TIME_ZONE> >> would >> be the default timezone for your project. >> >> With everything set, you can now use .activate() >> <https://docs.djangoproject.com/en/4.2/ref/utils/#django.utils.timezone.activate> >> available >> in `django.utils.timezone` to get the current time in your preferred >> timezone. >> >> I hope this answers your question. >> >> Best regards >> Reuben Sunday <https://reubensunday.com/> >> >> On Wed, Aug 16, 2023 at 3:35 AM Madhusudhan Reddy <[email protected]> >> wrote: >> >>> Hi All, >>> >>> I am trying to store the date with the timezone. >>> for example, my servers are in Mumbai, when my servers are trying to get >>> the time of America/Detroit. it is not able to get proper time >>> >>> Here is the snippet and details >>> [image: Screenshot from 2023-08-16 08-00-21.png] >>> def get_created_at(timezone): >>> local_tz = pytz.timezone(timezone) >>> print(datetime.utcnow()) >>> created_at = local_tz.localize(datetime.utcnow()).astimezone(tz=pytz. >>> timezone(timezone)) >>> return created_at >>> >>> >>> -- >>> Best regards, >>> Madhusudhan >>> +91 90007 79457 <+91%2090007%2079457> >>> Gmail | LinkedIn <https://www.linkedin.com/in/msreddygone/> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/CAFwQctLvw9KinV8a%3DVTysi_NSNJfu3rodBoBPCY5Cih_ih-DGQ%40mail.gmail.com >>> >>> <https://groups.google.com/d/msgid/django-users/CAFwQctLvw9KinV8a%3DVTysi_NSNJfu3rodBoBPCY5Cih_ih-DGQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAPUD46vztpvyb8P21vnBf9Wt2d2r6NQ-hgPDD3kyCc%2BpZu3siA%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/django-users/CAPUD46vztpvyb8P21vnBf9Wt2d2r6NQ-hgPDD3kyCc%2BpZu3siA%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a82a86a8-1ef6-480e-a8dd-5ef65476a78en%40googlegroups.com.

