From 3de4fae97782c82e427f5590664af1281082f3d3 Mon Sep 17 00:00:00 2001 From: Tukesh1 <115998898+Tukesh1@users.noreply.github.com> Date: Wed, 17 Sep 2025 20:11:46 +0530 Subject: [PATCH 1/2] docs: add asctime() term under python/time-module --- .../time-module/terms/asctime/asctime.md | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 content/python/concepts/time-module/terms/asctime/asctime.md diff --git a/content/python/concepts/time-module/terms/asctime/asctime.md b/content/python/concepts/time-module/terms/asctime/asctime.md new file mode 100644 index 00000000000..a40b58101fb --- /dev/null +++ b/content/python/concepts/time-module/terms/asctime/asctime.md @@ -0,0 +1,78 @@ +--- +Title: 'asctime()' +Description: 'Converts a time tuple or struct_time to a 24‑character human‑readable string.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Functions' + - 'Methods' + - 'Time' + - 'Python' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' +--- + +The **`time.asctime()`** Python function converts a time value (a 9‑element tuple or `time.struct_time`) into a readable, 24‑character string like `'Wed Sep 17 19:40:37 2025'`. + +## Syntax of `time.asctime()` + +```py +import time + +time.asctime(t) +time.asctime() # it uses current local time +``` + +**Parameters:** + +- `t` (optional): A 9‑tuple or `time.struct_time` representing a UTC or local time, with fields `(year, month, mday, hour, min, sec, wday, yday, isdst)` as produced by `time.localtime()` or `time.gmtime()`. + +**Return value:** + +- `str`: A 24‑character string of the form `'Sun Jun 20 23:21:05 1993'`. The day of month is two characters wide and space‑padded if needed (e.g., `'Wed Sep 17 19:40:37 2025'`). + +Notes: + +- If `t` is omitted, `time.asctime()` uses `time.localtime()`. +- `wday` (weekday) and `yday` (day of year) are ignored; `isdst` may be `-1`, `0`, or `1`. + +## Example + +Convert the current local time (from `localtime()`) and show the default call with no arguments: + +```py +import time + +# Using localtime() with asctime() +t = time.localtime() +lc = time.asctime(t) +print("Current local time represented in string:", lc) + +# Default call (formats current local time) +print(time.asctime()) +``` + +Example output: + +```shell +Current local time represented in string: Wed Sep 17 19:40:37 2025 +Wed Sep 17 19:40:37 2025 +``` + +## Codebyte + +Run this to see `time.asctime()` in action with local time, a UTC `struct_time`, and a custom tuple: + +```codebyte/python +import time + +# No argument → formats the current local time +print("Current local time:", time.asctime()) + +# Using an explicit 9-tuple +# Format: (year, month, day, hour, minute, second, weekday, yearday, isdst) +custom_time = (2025, 9, 17, 10, 30, 0, 0, 0, -1) +print("Custom tuple: ", time.asctime(custom_time)) +``` From 83c01973a34435e932197533bd01bc2eb7325780 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 29 Sep 2025 11:33:58 +0530 Subject: [PATCH 2/2] minor content fixes --- .../time-module/terms/asctime/asctime.md | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/content/python/concepts/time-module/terms/asctime/asctime.md b/content/python/concepts/time-module/terms/asctime/asctime.md index a40b58101fb..cc434da9651 100644 --- a/content/python/concepts/time-module/terms/asctime/asctime.md +++ b/content/python/concepts/time-module/terms/asctime/asctime.md @@ -1,43 +1,40 @@ --- Title: 'asctime()' -Description: 'Converts a time tuple or struct_time to a 24‑character human‑readable string.' +Description: 'Converts a time tuple or `struct_time` to a 24‑character human‑readable string.' Subjects: - 'Computer Science' - 'Data Science' Tags: - 'Functions' - 'Methods' - - 'Time' - 'Python' + - 'Time' CatalogContent: - 'learn-python-3' - 'paths/computer-science' --- -The **`time.asctime()`** Python function converts a time value (a 9‑element tuple or `time.struct_time`) into a readable, 24‑character string like `'Wed Sep 17 19:40:37 2025'`. +The **`time.asctime()`** Python function converts a time value (a 9‑element tuple or `time.struct_time`) into a readable, 24‑character string such as `'Wed Sep 17 19:40:37 2025'`. ## Syntax of `time.asctime()` -```py +```pseudo import time time.asctime(t) -time.asctime() # it uses current local time ``` **Parameters:** - `t` (optional): A 9‑tuple or `time.struct_time` representing a UTC or local time, with fields `(year, month, mday, hour, min, sec, wday, yday, isdst)` as produced by `time.localtime()` or `time.gmtime()`. + - If omitted, `time.asctime()` uses `time.localtime()`. + - `wday` (weekday) and `yday` (day of year) are ignored. + - `isdst` may be `-1`, `0`, or `1`. **Return value:** - `str`: A 24‑character string of the form `'Sun Jun 20 23:21:05 1993'`. The day of month is two characters wide and space‑padded if needed (e.g., `'Wed Sep 17 19:40:37 2025'`). -Notes: - -- If `t` is omitted, `time.asctime()` uses `time.localtime()`. -- `wday` (weekday) and `yday` (day of year) are ignored; `isdst` may be `-1`, `0`, or `1`. - ## Example Convert the current local time (from `localtime()`) and show the default call with no arguments: @@ -61,6 +58,8 @@ Current local time represented in string: Wed Sep 17 19:40:37 2025 Wed Sep 17 19:40:37 2025 ``` +> **Note:** The exact output will vary depending on when the function is run. + ## Codebyte Run this to see `time.asctime()` in action with local time, a UTC `struct_time`, and a custom tuple: @@ -74,5 +73,5 @@ print("Current local time:", time.asctime()) # Using an explicit 9-tuple # Format: (year, month, day, hour, minute, second, weekday, yearday, isdst) custom_time = (2025, 9, 17, 10, 30, 0, 0, 0, -1) -print("Custom tuple: ", time.asctime(custom_time)) +print("Custom tuple:", time.asctime(custom_time)) ```