0%

🪄 The Moment Is The Only Gift

Time prints itself quietly. This second will never repeat. Stay here, just this now.
🔮 print(time.strftime(“%H:%M:%S”))

The present moment is always slipping away. By the time you read this word, that second is gone. Never to return. Python can capture this fleeting gift. It asks the system for the current time and presents it like a delicate flower. The strftime() method stands for “string format time”. It takes a format string and returns a human readable representation of the current moment. Each percent sign followed by a letter is a time component waiting to be filled.

🕯️ Magic Note

The time module must be imported before use. time.strftime() without passing a time object uses the current local time. The format codes are the magic symbols. %H is the hour in 24 hour format (00 to 23). %M is the minute (00 to 59). %S is the second (00 to 61, accounting for leap seconds).

The syntax time.strftime(“%H:%M:%S”) asks the system for the current hour, minute, and second. Each code is replaced with its numerical value. The colons remain as separators. The result is a string like “14:35:22”. A snapshot of this exact moment in time.
  • Requires import time at the top of your script
  • %H gives 24 hour format (00 to 23)
  • %I (capital I) gives 12 hour format (01 to 12)
  • %p gives AM or PM for 12 hour clock
  • %M gives minutes, %S gives seconds
💡 Use %I:%M:%S %p for 12 hour clock with AM/PM like “02:35:22 PM”. Use %Y-%m-%d %H:%M:%S for full date and time like “2025-04-21 14:35:22”. Common codes: %Y (4 digit year), %m (month 01-12), %d (day 01-31), %A (full weekday name), %B (full month name).
Format CodeMeaningExample Output
%HHour (24 hour, 00-23)14
%IHour (12 hour, 01-12)02
%MMinute (00-59)35
%SSecond (00-61)22
%pAM or PMPM
%H:%M:%SFull 24 hour time14:35:22
⚠️ The time module must be imported before strftime() can be used. Calling time.strftime() without importing will raise a NameError. Also note that strftime() returns a string based on your system’s local time. For UTC, use time.gmtime() or the datetime module. Format codes are case sensitive, %m (month) is different from %M (minute).
Examples

Python

# Basic current time

import time

now = time.strftime(“%H:%M:%S”)

print(now)

# Output: 14:35:22 (current time will vary)

Python

# 12 hour clock with AM/PM

import time

now = time.strftime(“%I:%M:%S %p”)

print(now)

# Output: 02:35:22 PM (current time will vary)

Python

# Full date and time

import time

now = time.strftime(“%Y-%m-%d %H:%M:%S”)

print(now)

# Output: 2025-04-21 14:35:22 (current date and time will vary)

Common Mistakes
  • Forgetting to import the time module before using strftime()
  • Confusing %m (month) with %M (minute), they are case sensitive
  • Using %I (capital i) for hour but typing %l (lowercase L) which is not a valid code

⚡ Whisper

This second will never come again. The clock ticks forward. Silence between the beats. Python captures the now, prints it quietly, and lets it fade. Stay here. Just this moment. Just this gift.