You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
python-docx Document Timezone Issue - Help Request #1542
When using python-docx to generate Word documents and setting core_properties.created and core_properties.modified, the file timestamp shown in Windows Explorer is 8 hours ahead of the actual local time (Beijing Time, UTC+8).
Environment Information
Operating System: Windows 10/11
Python Version: Python 3.11
python-docx Version: Latest
Local Timezone: Beijing Time (UTC+8)
System Time: 13:45 (correct)
Word Document Displayed Time: 21:45 (incorrect, 8 hours ahead)
Reproduction Code
fromdocximportDocumentfromdatetimeimportdatetimedoc=Document()
# Set document metadata timestampscore_props=doc.core_propertiescore_props.created=datetime.now()
core_props.modified=datetime.now()
doc.save('test.docx')
Problem Analysis
After multiple tests, I found:
python-docx treats the passed datetime object as UTC time by default when storing
Windows system converts UTC time to local timezone (UTC+8) when displaying file properties
Result: System time 13:00 → docx stores as UTC 13:00 → Windows displays as 21:00 (UTC+8 conversion)
Current Workaround
fromdatetimeimportdatetime, timedelta# Pass "current time minus 8 hours" so Windows adds back 8 hours when displayingcorrect_time=datetime.now() -timedelta(hours=8)
doc.core_properties.created=correct_timedoc.core_properties.modified=correct_time
Questions
Is this a design bug or expected behavior in python-docx?
Is there a more elegant solution (without manually subtracting 8 hours)?
Should I pass timezone-aware datetime objects? (Tested but didn't work)
Expectations
Hoping the official team can provide:
Clear documentation on time handling
Or direct support for local timezone time setting
Dear community experts, is this a known issue? Are there any better solutions?
Activity
ismailcolakk13 commentedon Feb 27, 2026
You should use UTC time for better compatibility. Every system use UTC, its more compatible
const now = new Date();
const isoString = now.toISOString();
Fixes for timezone