Would it not make sense to store times in UCT then in a user profile allow 
the user to choose their local timezone for display?

On Wednesday, August 16, 2023 at 3:15:39 AM UTC-7 Ruby 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/4f45f203-9934-4cf2-b95c-c802449f2de3n%40googlegroups.com.

Reply via email to