Current Time Formatting Function

  • Share this:

Code introduction


This function gets the current time and formats it as 'YYYY-MM-DD HH:MM:SS'.


Technology Stack : datetime package, strftime method

Code Type : Function

Code Difficulty : Intermediate


                
                    
import datetime

def get_current_time():
    current_time = datetime.datetime.now()
    return current_time.strftime("%Y-%m-%d %H:%M:%S")