Python Forum
Help needed in finding a library for this project - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help needed in finding a library for this project (/thread-41333.html)



Help needed in finding a library for this project - PythonEnthusiast1729 - Dec-25-2023

Hey everyone, I just got an idea to make a automation project but I didn't know which library it needed. The automation project involves time, which means that the library should be able to detect time. For example this code should be able to check if it is 5PM or not in my PC. Could someone please suggest a library which can do this. I tried searching online for the library but I couldn't find any. Thank you


RE: Help needed in finding a library for this project - Pedroski55 - Dec-25-2023

Happy Christmas!

You need datetime! Look up the docs for all the %letter parameters.

from datetime import datetime

now = datetime.now()
print(now.strftime('Hour (00-11)          : %I'))
print(now.strftime('AM/PM                 : %p'))
print(now.strftime('%I%p'))
hour = now.strftime('%I%p')
if hour == '05PM':
    do something



RE: Help needed in finding a library for this project - PythonEnthusiast1729 - Dec-25-2023

Pedroski55 Wrote:You need datetime! Look up the docs for all the %letter parameters.
Hey Pedroski55, Thanks and Happy Christmas to you as well!. Snowman

Now finally thanks to you, I can learn more about this library and get started with my project


RE: Help needed in finding a library for this project - Larz60+ - Dec-25-2023

FYI: you may also want to take a look at Doug Hellmann's PYMOTW3 on datetime here.
This is an excellent write-up with many examples.


RE: Help needed in finding a library for this project - PythonEnthusiast1729 - Dec-26-2023

(Dec-25-2023, 04:25 PM)Larz60+ Wrote: FYI: you may also want to take a look at Doug Hellmann's PYMOTW3 on datetime here.
This is an excellent write-up with many examples.

Hey, @Larz60+, I just went through the document and it is actually very informative. I will make sure to learn the library from this document. Thanks!


RE: Help needed in finding a library for this project - PythonEnthusiast1729 - Dec-26-2023

I was just reading through the document and I couldn't find how to display the time now
They have showed us how to display todays date but not how to display the time at any exact moment
Could you please help me figure out how to display the time of any exact moment?
Thank you!


RE: Help needed in finding a library for this project - deanhystad - Dec-26-2023

On the mentioned website:
print('Now    :', datetime.datetime.now())



RE: Help needed in finding a library for this project - PythonEnthusiast1729 - Dec-27-2023

(Dec-26-2023, 04:39 PM)deanhystad Wrote: On the mentioned website:
print('Now    :', datetime.datetime.now())

Oh ok, This is how you do it

Thank you!