From fc85de4d8d2ae55c8d3c75ca5ff6a887f0fe2203 Mon Sep 17 00:00:00 2001 From: Lukas Kulas Date: Fri, 19 Sep 2025 16:31:51 +0800 Subject: [PATCH 1/3] Created the gmtime entry for python --- .../time-module/terms/gmtime/gmtime.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 content/python/concepts/time-module/terms/gmtime/gmtime.md diff --git a/content/python/concepts/time-module/terms/gmtime/gmtime.md b/content/python/concepts/time-module/terms/gmtime/gmtime.md new file mode 100644 index 00000000000..10fcabdf450 --- /dev/null +++ b/content/python/concepts/time-module/terms/gmtime/gmtime.md @@ -0,0 +1,38 @@ +The `gmtime()` function is used to convert a time value into a structured representation in Coordinated Universal Time (UTC). + +## Syntax + +```pseudo +gmtime([seconds]) +``` + +The optional argument `seconds` is the number of seconds since the epoch (January 1, 1970, 00:00:00 UTC). If no argument is provided, the function will use the current time. + +## Example + +```python +import time + +# Get the current time in UTC +current_time = time.gmtime() +print("Current UTC time:", current_time) + +# Convert a specific time (e.g., 1st January 2020) to UTC +specific_time = time.mktime((2020, 1, 1, 0, 0, 0, 0, 0, 0)) +utc_time = time.gmtime(specific_time) +print("Specific UTC time:", utc_time) +```e() function is used to convert a time value into a structured representation in Coordinated Universal Time (UTC). + +## Codebyte Example + +```python +import time + +# Get the current time in UTC +current_time = time.gmtime() +print("Current UTC time:", current_time) + +# Convert a specific time (e.g., 1st January 2020) to UTC +specific_time = time.mktime((2020, 1, 1, 0, 0, 0, 0, 0, 0)) +utc_time = time.gmtime(specific_time) +print("Specific UTC time:", utc_time) \ No newline at end of file From 1352ff68a959ab1243566f383ebe4f107942bbdf Mon Sep 17 00:00:00 2001 From: arisdelacruz <115809819+arisdelacruz@users.noreply.github.com> Date: Fri, 19 Sep 2025 16:40:40 +0800 Subject: [PATCH 2/3] Update gmtime.md --- .../time-module/terms/gmtime/gmtime.md | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/content/python/concepts/time-module/terms/gmtime/gmtime.md b/content/python/concepts/time-module/terms/gmtime/gmtime.md index 10fcabdf450..ee5fa993c51 100644 --- a/content/python/concepts/time-module/terms/gmtime/gmtime.md +++ b/content/python/concepts/time-module/terms/gmtime/gmtime.md @@ -1,3 +1,19 @@ +--- +Title: '.gmtime()' +Description: 'Converts a time expressed in seconds since the epoch to a struct_time in UTC.' +Subjects: + - 'Computer Science' + - 'Data Science' + - 'Web Development' +Tags: + - 'Methods' + - 'Constants' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' + - 'paths/front-end-engineer-career-path' +--- + The `gmtime()` function is used to convert a time value into a structured representation in Coordinated Universal Time (UTC). ## Syntax @@ -10,7 +26,7 @@ The optional argument `seconds` is the number of seconds since the epoch (Januar ## Example -```python +```py import time # Get the current time in UTC @@ -21,18 +37,14 @@ print("Current UTC time:", current_time) specific_time = time.mktime((2020, 1, 1, 0, 0, 0, 0, 0, 0)) utc_time = time.gmtime(specific_time) print("Specific UTC time:", utc_time) -```e() function is used to convert a time value into a structured representation in Coordinated Universal Time (UTC). +``` ## Codebyte Example -```python +```codebyte/python import time -# Get the current time in UTC -current_time = time.gmtime() -print("Current UTC time:", current_time) - -# Convert a specific time (e.g., 1st January 2020) to UTC -specific_time = time.mktime((2020, 1, 1, 0, 0, 0, 0, 0, 0)) -utc_time = time.gmtime(specific_time) -print("Specific UTC time:", utc_time) \ No newline at end of file +# Passing the seconds elapsed as an argument to this method +gt = time.gmtime(0) +print("The epoch of the system:", gt) +``` From 0ab3058222c2d64d62453609cd0942bf489729fd Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Tue, 23 Sep 2025 16:48:54 +0530 Subject: [PATCH 3/3] minor wording fix --- .../time-module/terms/gmtime/gmtime.md | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/content/python/concepts/time-module/terms/gmtime/gmtime.md b/content/python/concepts/time-module/terms/gmtime/gmtime.md index ee5fa993c51..465aa51255b 100644 --- a/content/python/concepts/time-module/terms/gmtime/gmtime.md +++ b/content/python/concepts/time-module/terms/gmtime/gmtime.md @@ -1,31 +1,38 @@ --- Title: '.gmtime()' -Description: 'Converts a time expressed in seconds since the epoch to a struct_time in UTC.' +Description: 'Converts a time expressed in seconds since the epoch to a `struct_time` in UTC.' Subjects: - 'Computer Science' - 'Data Science' - 'Web Development' Tags: - - 'Methods' - 'Constants' + - 'Methods' CatalogContent: - 'learn-python-3' - 'paths/computer-science' - - 'paths/front-end-engineer-career-path' --- -The `gmtime()` function is used to convert a time value into a structured representation in Coordinated Universal Time (UTC). +The **`gmtime()`** function converts a time value (in seconds since the epoch, or the current time if not provided) into a `struct_time` representation in Coordinated Universal Time (UTC). ## Syntax ```pseudo -gmtime([seconds]) +time.gmtime([seconds]) ``` -The optional argument `seconds` is the number of seconds since the epoch (January 1, 1970, 00:00:00 UTC). If no argument is provided, the function will use the current time. +**Parameters:** + +- `seconds` (optional, float or int): Number of seconds since the epoch (January 1, 1970, 00:00:00 UTC). If omitted, the current time is used. + +**Return value:** + +Returns a `time.struct_time` object in Coordinated Universal Time (UTC) with the attributes: `(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)` ## Example +In this example, the current UTC time is retrieved using `gmtime()`, and then a specific date (January 1, 2020) is converted into its UTC `struct_time` representation: + ```py import time @@ -39,8 +46,19 @@ utc_time = time.gmtime(specific_time) print("Specific UTC time:", utc_time) ``` +The possible output of this code is: + +```shell +Current UTC time: time.struct_time(tm_year=2025, tm_mon=9, tm_mday=23, tm_hour=11, tm_min=12, tm_sec=32, tm_wday=1, tm_yday=266, tm_isdst=0) +Specific UTC time: time.struct_time(tm_year=2020, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=1, tm_isdst=0) +``` + +> **Note:** The exact output for the current time will vary depending on when the code is executed. + ## Codebyte Example +In this example, 0 seconds since the epoch is passed to `gmtime()`, which returns the epoch start time in UTC: + ```codebyte/python import time