On 16/08/2023 12:35 pm, Madhusudhan Reddy 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

pytz is deprecated. You should consider using zoneinfo (install tzdata first) instead.

import zoneinfo
from datetime import datetime

tz = "America/Detroit"
rightnow = datetime.now(zoneinfo.ZoneInfo(tz))
datetime_in_tz = "%s-%s-%s %s:%02d:%02d" % (
        rightnow.year,
        rightnow.month,
        rightnow.day,
        rightnow.hour,
        rightnow.minute,
        rightnow.second,
)
print(f'{tz}:  {datetime_in_tz}')






Here is the snippet and details
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
Gmail <mailto:msreddy.g...@gmail.com> | 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 django-users+unsubscr...@googlegroups.com. 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>.


--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.

--
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ed002508-9995-eb11-9b99-9e2ea8b99885%40dewhirst.com.au.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to