Current Time Retrieval Function

  • Share this:

Code introduction


Retrieves the current time and returns it in a specified format.


Technology Stack : datetime

Code Type : Function

Code Difficulty : Intermediate


                
                    
import datetime

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