Easy to use timestamps in Python

I am working on a log type application in Python. The application basically allows the user to write log entries and adds a timestamp for a subsequent log request.

I am currently using the function time.ctime()to generate temporary stamps that are visually friendly. Thus, the log entries are as follows:

Thu Jan 21 19:59:47 2010 Did something
Thu Jan 21 20:01:07 2010 Did something else

Now, I would like to be able to use these timestamps to perform some searches / queries. I need to be able to search, for example, for "2010", or "feb 2010", or "February 23, 2010".

My questions:

1) What time module should be used: timevs datetime?

2) What would be a suitable way to create and use timestamp objects?

Many thanks!

+3
source share
2 answers

Option 1: do not change anything. Use time.strptime to analyze timestamps.

Option 2: switch to datetime. You can format timestamps in the same way and use datetime.strptime to parse them.

, . , . time . datetime.datetime . ; time . datetime. - - .

(90 , 3 ..) - datetime.

, datetime, .

+7

, ISO 8601. , , .

+9

Source: https://habr.com/ru/post/1729779/


All Articles