Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get timezone from Python C API?

Tags:

python

c

cpython

I don't find anything to find the timezone from a PyDateTime_DateTime. I want to get either the offset or the timezone name if possible.

Do you know how to do that ?

Thx

like image 243
EntrustName Avatar asked Mar 15 '26 04:03

EntrustName


1 Answers

There just isn't any C API accessor for a datetime's time zone. Your best option is to go through ordinary attribute access:

PyObject *tz_or_none = PyObject_GetAttrString(dt, "tzinfo");
like image 72
user2357112 supports Monica Avatar answered Mar 17 '26 17:03

user2357112 supports Monica