Write a Python program to get current time and date

Write a Python program to get current time and date

Program

from datetime import datetime
def myfun():
    time_now = datetime.now().strftime('%H:%M:%S')
    print(f'The time now is {time_now}')
            
if __name__=="__main__":
    myfun()


Output:

The time now is 10:15:50



from datetime import date
def myfun():
    today_date = date.today()
    print(today_date)
            
if __name__=="__main__":
    myfun()


Output:

2024-06-06


More Questions


18 . Write a Python program to get current time and date
19 . Write a Python program sort a list in descending order
20 . Python Program to Replace all Occurrences of ‘a’ with $ in a String
21 . Write a Python program to remove duplicates from a list
22 . Write a Python program to count number of vowels in the given string
23 . Write a Python program to check whether a character is an alphabet or not
24 . Write a Python program to count number of digits in an integer
25 . Write a Python program to print fibonacci series
26 . Write a Python program to print reverse number
27 . Write a Python Program to print Palindrome numbers from 1 to 100
28 . Write a Python Program to find the factorial of a number using recursion