top of page

Date and Time

# ------------ Working with Dates ---------
from datetime import datetime
date_obj=datetime.today()
print('The Month is:',date_obj.strftime('%m'))
print('The Day is:',date_obj.strftime('%d'))
print('The Year is:',date_obj.strftime('%Y'))

# ----------Working with Time 24HR ---------
print('\nThe Hour is:',date_obj.strftime('%H'))
print('The Minute is:',date_obj.strftime('%M'))
print('The Seconds is:',date_obj.strftime('%S'))

# ---------- Working with Time AM/PM -------
mydate_var = (date_obj.strftime("%I:%m %p"))
print("The Time is:",mydate_var)

# ---------- Other Options ------
current_year = datetime.now().year
print("The Year is:",current_year) 

# ---- Counter and Sleep ----
from time import *
X=10
while X > 0:
    print(X)
    X-=1
    sleep(1)

bottom of page