From abac8b7a4a14f58bd11c7a1eb797d3d869a625c0 Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 12:49:33 -0500 Subject: [PATCH 01/10] Create localtime.md --- .../time-module/terms/localtime/localtime.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 content/python/concepts/time-module/terms/localtime/localtime.md diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md new file mode 100644 index 00000000000..fe0edd5dbbf --- /dev/null +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -0,0 +1,44 @@ +--- +Title: 'The Title' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Description: 'A brief description.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) +Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! + - 'A subject name' + - 'A second subject name' + - 'An nth subject name' +Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! + - 'A tag' + - 'A second tag' + - 'An nth tag' +CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'learn-example-course' + - 'paths/example-path' +--- + +[A brief definition - make sure first mention of term is in **bold**.] + +## Syntax + +[Text, code, images, parameters, etc. about the syntax] + +## Example + +[Text, code, images, etc. about example 1] + +## Codebyte Example (if applicable) + +We can currently support: + +- Python +- JavaScript +- Ruby +- C++ +- C# +- Go +- PHP + +See [content-standards.md](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md) for more details! + +```codebyte/js +# Example runnable code block. +console.log('Hello, World!'); +``` From 13addc7f5c30d8779d7ec8ee3ce643ecdd035624 Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 12:57:27 -0500 Subject: [PATCH 02/10] Update localtime.md -Add Tags --- .../concepts/time-module/terms/localtime/localtime.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index fe0edd5dbbf..1749b832e7c 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -1,14 +1,13 @@ --- -Title: 'The Title' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Title: 'localtime' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed Description: 'A brief description.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! - 'A subject name' - 'A second subject name' - 'An nth subject name' -Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! - - 'A tag' - - 'A second tag' - - 'An nth tag' +Tags: + - 'Time' + - 'Python' CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first - 'learn-example-course' - 'paths/example-path' From aca871ccad917bd361b0b3e420ec4b7bfbe1bec6 Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 13:20:00 -0500 Subject: [PATCH 03/10] Update localtime.md Update Meta Data --- .../time-module/terms/localtime/localtime.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index 1749b832e7c..d46413f6e09 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -1,16 +1,14 @@ --- -Title: 'localtime' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed -Description: 'A brief description.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) -Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! - - 'A subject name' - - 'A second subject name' - - 'An nth subject name' +Title: '.localtime()' +Description: 'Converts the Python time to a local time relative to the geographical location of the system.' +Subjects: + - 'Code Foundations' Tags: - 'Time' - 'Python' -CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first - - 'learn-example-course' - - 'paths/example-path' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' --- [A brief definition - make sure first mention of term is in **bold**.] From 50e23fbba70abcafdc83951eac84a4a5238c1a53 Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 13:53:25 -0500 Subject: [PATCH 04/10] Update localtime.md --- .../python/concepts/time-module/terms/localtime/localtime.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index d46413f6e09..1918d386825 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -1,6 +1,6 @@ --- Title: '.localtime()' -Description: 'Converts the Python time to a local time relative to the geographical location of the system.' +Description: 'Converts a time, expressed in seconds since the epoch, and coverts it to the local time.' Subjects: - 'Code Foundations' Tags: @@ -11,7 +11,7 @@ CatalogContent: - 'paths/computer-science' --- -[A brief definition - make sure first mention of term is in **bold**.] +The `.localtime()` function converts a time, represented in seconds, to local time. If no time is passed, the current local time will be returned instead. ## Syntax From 98aae63d8212b9fca38f572336e0d521db45c1aa Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 13:54:27 -0500 Subject: [PATCH 05/10] Update localtime.md --- .../python/concepts/time-module/terms/localtime/localtime.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index 1918d386825..4a8909c5a15 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -15,7 +15,9 @@ The `.localtime()` function converts a time, represented in seconds, to local ti ## Syntax -[Text, code, images, parameters, etc. about the syntax] +```pseudo +time.localtime(seconds) +``` ## Example From 7916ecdc8cd603ad8998ae0b18dbf7543dcec94a Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 14:09:52 -0500 Subject: [PATCH 06/10] Update localtime.md Update Syntax --- .../concepts/time-module/terms/localtime/localtime.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index 4a8909c5a15..9c43fe5b1b3 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -11,7 +11,7 @@ CatalogContent: - 'paths/computer-science' --- -The `.localtime()` function converts a time, represented in seconds, to local time. If no time is passed, the current local time will be returned instead. +The `.localtime()` methord converts a time, represented in seconds, to local time. If no time is passed, the current local time will be returned instead. ## Syntax @@ -19,6 +19,14 @@ The `.localtime()` function converts a time, represented in seconds, to local ti time.localtime(seconds) ``` +**Parameters:** + +- `seconds`: (Optional) A floating-point number representing the number of seconds elapsed. + +**Return value:** + +Returns the time elapsed since the epoch in a system as an object. + ## Example [Text, code, images, etc. about example 1] From 2664e6731196f221ec7cff13eeaf550a8f3fc3d3 Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 14:56:24 -0500 Subject: [PATCH 07/10] Update localtime.md Update Examples --- .../time-module/terms/localtime/localtime.md | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index 9c43fe5b1b3..2eb321763df 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -27,7 +27,38 @@ time.localtime(seconds) Returns the time elapsed since the epoch in a system as an object. -## Example +## Example 1: `.localtime()` With No Argument +This example demonstrates when running `.localtime()` without the optional seconds argument + +```py +import time + +lt = time.localtime() +print('Current Local Time:', lt) +``` + +The output of the code is: + +``` +Current local time: time.struct_time(tm_year=2025, tm_mon=8, tm_mday=31, tm_hour=19, tm_min=53, tm_sec=36, tm_wday=6, tm_yday=243, tm_isdst=0) +``` + +## Example 2: `.localtime()` With a Passed Argument +In the example below, we are trying to find the date after 5000 seconds from the epoch. + +``` +import time + +# Passing the seconds elapsed as an argument to this method +lt = time.localtime(5000) +Print('Python Local Time:', lt) +``` + +The output of the code is: + +``` +Python local time: time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=1, tm_min=23, tm_sec=20, tm_wday=3, tm_yday=1, tm_isdst=0) +``` [Text, code, images, etc. about example 1] From 012d56aee6fe9ec4752ce6e44c81cc0573212458 Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 16:10:12 -0500 Subject: [PATCH 08/10] Update localtime.md --- .../time-module/terms/localtime/localtime.md | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index 2eb321763df..99fd81c38ea 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -60,23 +60,11 @@ The output of the code is: Python local time: time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=1, tm_min=23, tm_sec=20, tm_wday=3, tm_yday=1, tm_isdst=0) ``` -[Text, code, images, etc. about example 1] +## Codebyte Example -## Codebyte Example (if applicable) - -We can currently support: - -- Python -- JavaScript -- Ruby -- C++ -- C# -- Go -- PHP - -See [content-standards.md](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md) for more details! +```codebyte/py +import time -```codebyte/js -# Example runnable code block. -console.log('Hello, World!'); +lt = time.localtime() +print('Current Local Time:', lt) ``` From ae602858c0a26bbc6b8bd958543042aaf543662f Mon Sep 17 00:00:00 2001 From: LowLifeCrisis Date: Sun, 31 Aug 2025 16:12:31 -0500 Subject: [PATCH 09/10] Update localtime.md --- .../concepts/time-module/terms/localtime/localtime.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index 99fd81c38ea..47c31eac4e8 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -60,11 +60,3 @@ The output of the code is: Python local time: time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=1, tm_min=23, tm_sec=20, tm_wday=3, tm_yday=1, tm_isdst=0) ``` -## Codebyte Example - -```codebyte/py -import time - -lt = time.localtime() -print('Current Local Time:', lt) -``` From b66fb4c92d07770ab08043c44ef69a7194ca1524 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 1 Sep 2025 18:35:32 +0530 Subject: [PATCH 10/10] minor fixes --- .../time-module/terms/localtime/localtime.md | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/content/python/concepts/time-module/terms/localtime/localtime.md b/content/python/concepts/time-module/terms/localtime/localtime.md index 47c31eac4e8..8c39c066621 100644 --- a/content/python/concepts/time-module/terms/localtime/localtime.md +++ b/content/python/concepts/time-module/terms/localtime/localtime.md @@ -1,17 +1,18 @@ --- Title: '.localtime()' -Description: 'Converts a time, expressed in seconds since the epoch, and coverts it to the local time.' +Description: 'Converts a time expressed in seconds since the epoch to the local time.' Subjects: - 'Code Foundations' + - 'Computer Science' Tags: - - 'Time' - 'Python' + - 'Time' CatalogContent: - 'learn-python-3' - 'paths/computer-science' --- -The `.localtime()` methord converts a time, represented in seconds, to local time. If no time is passed, the current local time will be returned instead. +The **`.localtime()`** method converts a time value, given in seconds since the epoch (January 1, 1970, 00:00:00 UTC), into local time. If no value is provided, it returns the current local time instead. ## Syntax @@ -21,14 +22,15 @@ time.localtime(seconds) **Parameters:** -- `seconds`: (Optional) A floating-point number representing the number of seconds elapsed. +- `seconds`(Optional): A number (float or int) representing seconds since the epoch. Defaults to the current time if omitted. **Return value:** -Returns the time elapsed since the epoch in a system as an object. +Returns a `time.struct_time` object representing the local time. -## Example 1: `.localtime()` With No Argument -This example demonstrates when running `.localtime()` without the optional seconds argument +## Example 1: `.localtime()` With No Argument + +This example demonstrates when running `.localtime()` without the optional seconds argument: ```py import time @@ -39,24 +41,38 @@ print('Current Local Time:', lt) The output of the code is: -``` +```shell Current local time: time.struct_time(tm_year=2025, tm_mon=8, tm_mday=31, tm_hour=19, tm_min=53, tm_sec=36, tm_wday=6, tm_yday=243, tm_isdst=0) ``` -## Example 2: `.localtime()` With a Passed Argument -In the example below, we are trying to find the date after 5000 seconds from the epoch. +## Example 2: `.localtime()` With a Passed Argument -``` +In the example below, we are trying to convert 5000 seconds since the epoch into local time: + +```py import time # Passing the seconds elapsed as an argument to this method lt = time.localtime(5000) -Print('Python Local Time:', lt) +print('Python Local Time:', lt) ``` The output of the code is: -``` +```shell Python local time: time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=1, tm_min=23, tm_sec=20, tm_wday=3, tm_yday=1, tm_isdst=0) ``` +## Codebyte Example: `.localtime()` Used to Log a File Download Time + +This example demonstrates how to record the local time when a file download is completed: + +```codebyte/python +import time + +# Simulate logging the time of a file download +download_time = time.localtime() +print("File downloaded at:", time.strftime("%Y-%m-%d %H:%M:%S", download_time)) +``` + +> **Note:** The output of `.localtime()` may differ depending on the system clock, time zone settings, and daylight saving adjustments.