python time function in for loop 1

python time function in for loop

from datetime import datetime

def currenttime():
    now = datetime.now()
    dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
    return dt_string

Here is what the above code is Doing:
1. We import the datetime module.
2. We create a function called currenttime() that takes no arguments.
3. We create a variable called now that stores the current date and time.
4. We create a variable called dt_string that stores the current date and time in a string format.
5. We return the dt_string variable.
6. We call the currenttime() function and print the result.

Similar Posts