Skip to content
Advertisement

Tag: time

Difference between Python datetime vs time modules

I am trying to figure out the differences between the datetime and time modules, and what each should be used for. I know that datetime provides both dates and time. What is the use of the time module? Examples would be appreciated and differences concerning timezones would especially be of interest. Answer The time module is principally for working with

Python logging: use milliseconds in time format

By default logging.Formatter(‘%(asctime)s’) prints with the following format: where 638 is the millisecond. I need to change the comma to a dot: To format the time I can use: however the documentation doesn’t specify how to format milliseconds. I’ve found this SO question which talks about microseconds, but a) I would prefer milliseconds and b) the following doesn’t work on

Checking date against date range in Python

I have a date variable: 2011-01-15 and I would like to get a boolean back if said date is within 3 days from TODAY. Im not quite sure how to construct this in Python. Im only dealing with date, not datetime. My working example is a “grace period”. A user logs into my site and if the grace period is

User-friendly time format in Python?

Python: I need to show file modification times in the “1 day ago”, “two hours ago”, format. Is there something ready to do that? It should be in English. Answer The code was originally published on a blog post “Python Pretty Date function” (http://evaisse.com/post/93417709/python-pretty-date-function) It is reproduced here as the blog account has been suspended and the page is no

Advertisement