Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the datetime module, the datetime, time, and timedelta classes all have the smallest resolution of microseconds:</p> <pre><code>&gt;&gt;&gt; from datetime import datetime, timedelta &gt;&gt;&gt; now = datetime.now() &gt;&gt;&gt; now datetime.datetime(2009, 12, 4, 23, 3, 27, 343000) &gt;&gt;&gt; now.microsecond 343000 </code></pre> <p>if you want to display a datetime with fractional seconds, just insert a decimal point and strip trailing zeros:</p> <pre><code>&gt;&gt;&gt; now.strftime("%Y-%m-%d %H:%M:%S.%f").rstrip('0') '2009-12-04 23:03:27.343' </code></pre> <p>the datetime and time classes only accept integer input and hours, minutes and seconds must be between 0 to 59 and microseconds must be between 0 and 999999. The timedelta class, however, will accept floating point values with fractions and do all the proper modulo arithmetic for you:</p> <pre><code>&gt;&gt;&gt; span = timedelta(seconds=3662.567) &gt;&gt;&gt; span datetime.timedelta(0, 3662, 567000) </code></pre> <p>The basic components of timedelta are day, second and microsecond (0, 3662, 567000 above), but the constructor will also accept milliseconds, hours and weeks. All inputs may be integers or floats (positive or negative). All arguments are converted to the base units and then normalized so that 0 &lt;= seconds &lt; 60 and 0 &lt;= microseconds &lt; 1000000.</p> <p>You can add or subtract the span to a datetime or time instance or to another span. Fool around with it, you can probably easily come up with some functions or classes to do exaxtly what you want. You could probably do all your date/time processing using timedelta instances relative to some fixed datetime, say <code>basetime = datetime(2000,1,1,0,0,0)</code>, then convert to a datetime or time instance for display or storage.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload