2 Replies - 828 Views - Last Post: 19 August 2013 - 10:27 AM Rate Topic: -----

#1 liherb  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 25-November 12

datetime vs. time module

Posted 19 August 2013 - 12:38 AM

I'm a python newbie and recently really have been scratching my head to figure out the advantages and disadvantages of two standard modules dealing with time: datetime vs. time. According to the documentation, they are serving quite same purpose. Is one better or faster than the other?
Generally speaking, under what circumstances I should use datetime, or time? Could some pros give some insight here? many thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: datetime vs. time module

#2 Mekire  Icon User is offline

  • D.I.C Head

Reputation: 116
  • View blog
  • Posts: 212
  • Joined: 11-January 13

Re: datetime vs. time module

Posted 19 August 2013 - 02:16 AM

The time module is generally used for timing how long simple things take and making the program pause for a desired length of time. The datetime module, on the other hand, is for doing calculations with dates and times. If you want to know how many days passed between a given date and another date (for example), datetime is the guy.

There is also another module called timeit for more accurate feature filled methods of timing code.

-Mek

This post has been edited by Mekire: 19 August 2013 - 02:17 AM

Was This Post Helpful? 1
  • +
  • -

#3 liherb  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 25-November 12

Re: datetime vs. time module

Posted 19 August 2013 - 10:27 AM

Thanks Mek. If I want to parse arbitary string containing time information, neither module seems to be able to do the job. Is there a recommended pattern to parse it without resorting regex?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1