You can download this code by clicking the button below.
This code is now available for download.
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)