Created
October 26, 2020 11:48
-
-
Save pandorica-opens/3fcf85437010c758262e09a2f56e2bd7 to your computer and use it in GitHub Desktop.
The file_date function creates a new file in the current working directory, checks the date that the file was modified, and returns just the date portion of the timestamp in the format of yyyy-mm-dd.
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
| def file_date(filename): | |
| # Create the file in the current directory | |
| # For mknod the root priveleges are required | |
| os.mknod(filename) | |
| timestamp = os.path.getmtime(filename) | |
| # Convert the timestamp into a readable format, then into a string | |
| time = datetime.datetime.fromtimestamp(timestamp) | |
| time = str(time) | |
| # Return just the date portion | |
| # Hint: how many characters are in “yyyy-mm-dd”? | |
| return ("{:.10s}".format(time)) | |
| print(file_date("newfile.txt")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment