-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
gh-137758: Clarify os.stat_result time fields (since Unix epoch) and add datetime conversion note #137761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tangyuan0821
wants to merge
7
commits into
python:main
Choose a base branch
from
tangyuan0821:main2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−12
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… the Unix epoch Clarify that `os.stat_result` time fields (`st_atime`, `st_mtime`, `st_ctime`, `st_birthtime`) and their `*_ns` variants are measured since the Unix epoch (00:00:00 UTC, 1970-01-01). Add a short note showing how to convert these timestamps to `datetime` using `datetime.datetime.fromtimestamp`, including a UTC example. Documentation-only; no behavior change. Files touched: Doc/library/os.rst Co-authored-by: tangyuan0821 <tangyuan0821@hotmail.com>
…indicate that it is the number of seconds since the Unix epoch.
nedbat
approved these changes
Aug 14, 2025
StanFromIreland
requested changes
Aug 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not use the Update Branch button unless necessary (e.g. fixing conflicts, jogging the CI, or very old PRs) as it uses valuable resources. For more information see the devguide. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
st_atime
,st_mtime
,st_ctime
,st_birthtime
and their*_ns
variants) are measured since the Unix epoch (00:00:00 UTC, 1970-01-01).datetime
usingdatetime.fromtimestamp()
and UTC example.Linked issue:
Changes:
st_atime
,st_mtime
,st_ctime
→ “seconds since the epoch”.st_atime_ns
,st_mtime_ns
,st_ctime_ns
→ “nanoseconds since the epoch”.st_birthtime
,st_birthtime_ns
→ explicitly reference the epoch.time.time
; includedatetime
conversion examples.📚 Documentation preview 📚: https://cpython-previews--137761.org.readthedocs.build/