Python - как работать со временем без головной боли

Python – how to work with time without headache?

Hi all! Working with time in Python is a different story (and headache). And today we will deal with the problem: how to work with time without a headache (yes, this is quite real)?

A library will come to the rescue (oh, these libraries, how well they complement the gloominess and severity of life!) arrow – documentation on which you can find here. It looks like this:

import arrow #Include the library to work with time
now = arrow.now() #Create a variable that contains the current time value
print(now) #For example - print everything related to NOW
print(now.time()) #Now print just the current time
print(now.date()) #Or - the current dateprint(now.humanize(locale='ru')) #Now let's see what happens with this command? :)
print(now.shift(hours=-1).humanize(locale='ru')) #And now we will display in text how the time will look an hour ago
print(now.shift(hours=+1).humanize(locale='ru')) #Or - time in an hour

The output looks like this:
2022-01-24T22:46:44.667269+01:00
22:46:44.667269
2022-01-24
now
Hour ago
in one hour

As you can see – work over time can be without a headache;) And yes – this is the very basics. The library itself offers more complete and interesting functionality that allows you to make your program more human.

Thanks for attention. As always, if you have any questions, write to mail or Telegram.