Skip to content

Commit 29b558e

Browse files
committed
Datetime
1 parent d234829 commit 29b558e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ from dateutil.tz import UTC, tzlocal, gettz
563563
<DTn> = DT.utcnow() # Naive datetime from current UTC time.
564564
<DTa> = DT.now(<tzinfo>) # Aware datetime from current tz time.
565565
```
566-
* **To extract time use `'<DTn>.time()'` or `'<DTa>.timetz()'`.**
566+
* **To extract time use `'<DTn>.time()'`, `'<DTa>.time()'` or `'<DTa>.timetz()'`.**
567567

568568
### Timezone
569569
```python
@@ -581,8 +581,9 @@ from dateutil.tz import UTC, tzlocal, gettz
581581
```python
582582
<D/T/DT> = D/T/DT.fromisoformat('<iso>') # Object from ISO string.
583583
<DT> = DT.strptime(<str>, '<format>') # Datetime from str, according to format.
584-
<D/DTn> = D/DT.fromordinal(<int>) # D/DTn from days since Christ.
585-
<DTa> = DT.fromtimestamp(<real>, <tz.>) # DTa from seconds since Epoch in tz time.
584+
<D/DTn> = D/DT.fromordinal(<int>) # D/DTn from days since Christ, at midnight.
585+
<DTn> = DT.fromtimestamp(<real>) # Local time DTn from seconds since Epoch.
586+
<DTa> = DT.fromtimestamp(<real>, <tz.>) # Aware datetime from seconds since Epoch.
586587
```
587588
* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±<offset>]'`, or both separated by `'T'`. Offset is formatted as: `'HH:MM'`.**
588589
* **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...**
@@ -592,7 +593,8 @@ from dateutil.tz import UTC, tzlocal, gettz
592593
<str> = <D/T/DT>.isoformat() # ISO string representation.
593594
<str> = <D/T/DT>.strftime('<format>') # Custom string representation.
594595
<int> = <D/DT>.toordinal() # Days since Christ, ignoring time and tz.
595-
<float> = <DT>.timestamp() # Seconds since Epoch in local time or tz.
596+
<float> = <DTn>.timestamp() # Seconds since Epoch from DTn in local time.
597+
<float> = <DTa>.timestamp() # Seconds since Epoch from DTa.
596598
```
597599

598600
### Format

index.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ <h3 id="now">Now</h3>
602602
&lt;DTa&gt; = DT.now(&lt;tzinfo&gt;) <span class="hljs-comment"># Aware datetime from current tz time.</span>
603603
</code></pre>
604604
<ul>
605-
<li><strong>To extract time use <code class="python hljs"><span class="hljs-string">'&lt;DTn&gt;.time()'</span></code> or <code class="python hljs"><span class="hljs-string">'&lt;DTa&gt;.timetz()'</span></code>.</strong></li>
605+
<li><strong>To extract time use <code class="python hljs"><span class="hljs-string">'&lt;DTn&gt;.time()'</span></code>, <code class="python hljs"><span class="hljs-string">'&lt;DTa&gt;.time()'</span></code> or <code class="python hljs"><span class="hljs-string">'&lt;DTa&gt;.timetz()'</span></code>.</strong></li>
606606
</ul>
607607
<h3 id="timezone">Timezone</h3>
608608
<pre><code class="python language-python hljs">&lt;tzinfo&gt; = UTC <span class="hljs-comment"># UTC timezone. London without DST.</span>
@@ -615,18 +615,20 @@ <h3 id="timezone">Timezone</h3>
615615
<h3 id="encode">Encode</h3>
616616
<pre><code class="python language-python apache hljs">&lt;D/T/DT&gt; = D/T/DT.fromisoformat(<span class="hljs-string">'&lt;iso&gt;'</span>) <span class="hljs-comment"># Object from ISO string.</span>
617617
&lt;DT&gt; = DT.strptime(&lt;str&gt;, <span class="hljs-string">'&lt;format&gt;'</span>) <span class="hljs-comment"># Datetime from str, according to format.</span>
618-
&lt;D/DTn&gt; = D/DT.fromordinal(&lt;int&gt;) <span class="hljs-comment"># D/DTn from days since Christ.</span>
619-
&lt;DTa&gt; = DT.fromtimestamp(&lt;real&gt;, &lt;tz.&gt;) <span class="hljs-comment"># DTa from seconds since Epoch in tz time.</span>
618+
&lt;D/DTn&gt; = D/DT.fromordinal(&lt;int&gt;) <span class="hljs-comment"># D/DTn from days since Christ, at midnight.</span>
619+
&lt;DTn&gt; = DT.fromtimestamp(&lt;real&gt;) <span class="hljs-comment"># Local time DTn from seconds since Epoch.</span>
620+
&lt;DTa&gt; = DT.fromtimestamp(&lt;real&gt;, &lt;tz.&gt;) <span class="hljs-comment"># Aware datetime from seconds since Epoch.</span>
620621
</code></pre>
621622
<ul>
622623
<li><strong>ISO strings come in following forms: <code class="python hljs"><span class="hljs-string">'YYYY-MM-DD'</span></code>, <code class="python hljs"><span class="hljs-string">'HH:MM:SS.ffffff[±&lt;offset&gt;]'</span></code>, or both separated by <code class="python hljs"><span class="hljs-string">'T'</span></code>. Offset is formatted as: <code class="python hljs"><span class="hljs-string">'HH:MM'</span></code>.</strong></li>
623624
<li><strong>On Unix systems Epoch is <code class="python hljs"><span class="hljs-string">'1970-01-01 00:00 UTC'</span></code>, <code class="python hljs"><span class="hljs-string">'1970-01-01 01:00 CET'</span></code>, …</strong></li>
624625
</ul>
625626
<h3 id="decode">Decode</h3>
626-
<pre><code class="python language-python apache hljs">&lt;str&gt; = &lt;D/T/DT&gt;.isoformat() <span class="hljs-comment"># ISO string representation.</span>
627+
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;D/T/DT&gt;.isoformat() <span class="hljs-comment"># ISO string representation.</span>
627628
&lt;str&gt; = &lt;D/T/DT&gt;.strftime(<span class="hljs-string">'&lt;format&gt;'</span>) <span class="hljs-comment"># Custom string representation.</span>
628629
&lt;int&gt; = &lt;D/DT&gt;.toordinal() <span class="hljs-comment"># Days since Christ, ignoring time and tz.</span>
629-
&lt;float&gt; = &lt;DT&gt;.timestamp() <span class="hljs-comment"># Seconds since Epoch in local time or tz.</span>
630+
&lt;float&gt; = &lt;DTn&gt;.timestamp() <span class="hljs-comment"># Seconds since Epoch from DTn in local time.</span>
631+
&lt;float&gt; = &lt;DTa&gt;.timestamp() <span class="hljs-comment"># Seconds since Epoch from DTa.</span>
630632
</code></pre>
631633
<h3 id="format-1">Format</h3>
632634
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime

0 commit comments

Comments
 (0)