Python: How to print out AM/PM time format every 3 mins throughout the day


First, let’s warm up with some functions about time/date.

The purpose for doing such kind of boring things is for implementation requirements of the scheduler I will use in Windows environment.


How many iterations for every 3 mins:


My first thought print out lines of time 480 times, so I can get an array of times and output what I want

  • Use while loop to set iterations
  • Use another variable to get each offset
  • Increment variable to make it reach to the up limit of iteration




Copy the outputs to a text file, though this is not a good ideal since I am a beginner for python language. In the future, I will learn how to dump them to the file


Run python to get the results




Real-life scenario:


I can’t use Windows tasker to schedule scripts to run periodically due to insufficient permission(God knows maybe I am not a power user or admin user on that machine, but I want to run script to sync my data from source to target every 3 mins)


I found a free edition scheduler from following links called “Freebyte Task Scheduler”

Top 5 Windows Task Scheduler Alternatives

However due to its limitation, I can’t create tasks in batch to define a script to run every 3 minutes in a day, that’s really a lot of work for me to complete, totally 480 tasks needs to be created with unique name and time and ten more duplicated parameters.


Thanks to the author of this program I could understand the logic of its configuration file ‘FBTaskScheduler.ini’




Only two lines I need to put variables there, other lines keep the same

I wrote a bash script as follows:


Then I copy this config file FBTaskScheduler.ini to the same path of executable file.

Boom! Magic shows:

Nice work we done.

To recap: Some things you can take back

  • To convert time from 24hrs to 12hrs (AM/PM)
  • Use python to write while loop to get your results that has certain digits regularity
  • Python need to import modules before you need use special functions
  • In Windows CMD, if you want to make Windows CMD as program, script as parameters, please ensure you use double quotes instead of single quote, single quote will not make it run per my test.




Leave a Reply

Your email address will not be published. Required fields are marked *