TGViewer
Learn Python Coding Learn Python Coding @pythonre · 40.8K subscribers
Post #9210 1.51K
A bit of Python basics. Day 4: Getting the current time and date

The code below shows how to get the current time using the datetime module. The now() method returns a datetime object representing the current date and time according to the system clock. The strftime() method formats the time for the desired output. This code shows how to use the datetime module together with the strftime() method to get a formatted time string in the format of hours, minutes, and seconds.

from datetime import datetime

time_now = datetime.now().strftime('%H:%M:%S')
print(f'Current time: {time_now}')


Current time: 17:37:28


What if we want to return today's date? We can use date from the datetime module. Below, the today() method is used:

from datetime import date

today_date = date.today()
print(today_date)


2023-09-20


👉 https://t.me/DataScience4
  • ❤ 1
More from @pythonre
  1. Oct 10, 2026📚 Download 10 Python books for FREE: 1. Think Python — O’Reilly https://t.co/X7y3pX68IW 2…
  2. Oct 7, 2026Python Lists: A Quick Reference 🐍 * Definition: Lists are ordered, mutable collections th…
  3. Oct 7, 2026📱 270 tools for Python developers The repository contains: 🫡 Linters and formatters; 🫡…
  4. Oct 7, 2026Hands On Python Data Science - Data Science Bootcamp Master Python for Data Science with R…
  5. Oct 6, 2026Post #9851
  6. Oct 6, 2026Python For Beginners Course In-Depth Python: A Comprehensive Introduction to Fundamental P…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →