How to Get Current Time in AM/PM Format using Python

In this tutorial, we will program 'How to Get the Current Time in Python.' We will learn how to get the current time and display it. The objective is to extract the current time based on your computer. I will provide a sample program to demonstrate the actual coding process in this tutorial.

This topic is very easy to understand. Just follow the instructions I provide, and you can do it yourself with ease. The program I will show you covers the basics of programming to get the current time. I will do my best to provide you with a simple method for getting the correct time. So, let's start with the coding.

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. from datetime import datetime
  2.  
  3.  
  4. now_method = datetime.now()
  5.  
  6.  
  7. currentTime = now_method.strftime("%I:%M%p")
  8.  
  9. print("\n\n================= Get Current Time =================")
  10. print("\n")
  11.  
  12. print("Current Time =", currentTime)

This script fetches the current date and time, formats the time to a 12-hour clock with AM/PM, and prints it. It provides a simple way to display the current time in a human-readable format.

Output:

There you have it we successfully created How to Get Current Time in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment