You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-11Lines changed: 17 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -561,27 +561,28 @@ from dateutil.tz import UTC, tzlocal, gettz
561
561
```python
562
562
<D/DTn>= D/DT.today() # Current local date or naive datetime.
563
563
<DTn>=DT.utcnow() # Naive datetime from current UTC time.
564
-
<DTa>=DT.now(<tz>) # Aware datetime from current tz time.
564
+
<DTa>=DT.now(<tzinfo>)# Aware datetime from current tz time.
565
565
```
566
+
***To extract time use `'<DTn>.time()'` or `'<DTa>.timetz()'`.**
566
567
567
568
### Timezone
568
569
```python
569
-
<tz>=UTC# UTC timezone. London without DST.
570
-
<tz>= tzlocal() # Local timezone.
571
-
<tz>= gettz('<Cont.>/<City>') # Timezone from 'Continent/City_Name' str.
570
+
<tzinfo>=UTC# UTC timezone. London without DST.
571
+
<tzinfo>= tzlocal() # Local timezone.
572
+
<tzinfo>= gettz('<Cont.>/<City>') # Timezone from 'Continent/City_Name' str.
572
573
```
573
574
574
575
```python
575
-
<DTa>=<DT>.astimezone(<tz>) # Datetime, converted to passed timezone.
576
-
<Ta/DTa>=<T/DT>.replace(tzinfo=<tz>) # Unconverted object with new timezone.
576
+
<DTa>=<DT>.astimezone(<tzinfo>)# Datetime, converted to passed timezone.
577
+
<Ta/DTa>=<T/DT>.replace(tzinfo=<tzinfo>)# Unconverted object with new timezone.
577
578
```
578
579
579
580
### Encode
580
581
```python
581
582
<D/T/DT>= D/T/DT.fromisoformat('<iso>') # Object from ISO string.
582
583
<DT>=DT.strptime(<str>, '<format>') # Datetime from str, according to format.
583
584
<D/DTn>= D/DT.fromordinal(<int>) # D/DTn from days since Christ.
584
-
<DTa>=DT.fromtimestamp(<real>, <tz>) # DTa from seconds since Epoch in tz time.
585
+
<DTa>=DT.fromtimestamp(<real>, <tz.>)# DTa from seconds since Epoch in tz time.
585
586
```
586
587
***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'`.**
587
588
***On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...**
@@ -601,10 +602,15 @@ from dateutil.tz import UTC, tzlocal, gettz
601
602
>>> dt.strftime("%A, %dth of %B '%y, %I:%M%p %Z")
602
603
"Thursday, 14th of May '15, 11:39PM UTC+02:00"
603
604
```
605
+
***For abbreviated weekday and month use `'%a'` and `'%b'`.**
604
606
605
-
#### Rest of the codes:
606
-
***`'a'` - Weekday, abbreviated name.**
607
-
***`'b'` - Month, abbreviated name.**
607
+
### Arithmetics
608
+
```python
609
+
<D/DT>=<D/DT> ± <TD>
610
+
<TD>=<TD> ± <TD>
611
+
<TD>=<TD>*/<real>
612
+
<float>=<TD>/<TD>
613
+
```
608
614
609
615
610
616
Arguments
@@ -1350,7 +1356,7 @@ cwd = Path()
1350
1356
```
1351
1357
1352
1358
```python
1353
-
<iter>=<Path>.iterdir() # Iterator with filenames located at path.
1359
+
<iter>=<Path>.iterdir() # Iterator of filenames located at path.
1354
1360
<iter>=<Path>.glob('<pattern>') # Filenames matching the wildcard pattern.
<pre><codeclass="python language-python hljs"><D/DTn> = D/DT.today() <spanclass="hljs-comment"># Current local date or naive datetime.</span>
601
601
<DTn> = DT.utcnow() <spanclass="hljs-comment"># Naive datetime from current UTC time.</span>
602
-
<DTa> = DT.now(<tz>)<spanclass="hljs-comment"># Aware datetime from current tz time.</span>
602
+
<DTa> = DT.now(<tzinfo>) <spanclass="hljs-comment"># Aware datetime from current tz time.</span>
603
603
</code></pre>
604
+
<ul>
605
+
<li><strong>To extract time use <codeclass="python hljs"><spanclass="hljs-string">'<DTn>.time()'</span></code> or <codeclass="python hljs"><spanclass="hljs-string">'<DTa>.timetz()'</span></code>.</strong></li>
606
+
</ul>
604
607
<h3id="timezone">Timezone</h3>
605
-
<pre><codeclass="python language-python hljs"><tz> = UTC <spanclass="hljs-comment"># UTC timezone. London without DST.</span>
606
-
<tz> = tzlocal() <spanclass="hljs-comment"># Local timezone.</span>
607
-
<tz> = gettz(<spanclass="hljs-string">'<Cont.>/<City>'</span>) <spanclass="hljs-comment"># Timezone from 'Continent/City_Name' str.</span>
608
+
<pre><codeclass="python language-python hljs"><tzinfo> = UTC <spanclass="hljs-comment"># UTC timezone. London without DST.</span>
609
+
<tzinfo> = tzlocal() <spanclass="hljs-comment"># Local timezone.</span>
610
+
<tzinfo> = gettz(<spanclass="hljs-string">'<Cont.>/<City>'</span>) <spanclass="hljs-comment"># Timezone from 'Continent/City_Name' str.</span>
<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) <spanclass="hljs-comment"># Unconverted object with new timezone.</span>
611
614
</code></pre>
612
615
<h3id="encode">Encode</h3>
613
616
<pre><codeclass="python language-python apache hljs"><D/T/DT> = D/T/DT.fromisoformat(<spanclass="hljs-string">'<iso>'</span>) <spanclass="hljs-comment"># Object from ISO string.</span>
614
617
<DT> = DT.strptime(<str>, <spanclass="hljs-string">'<format>'</span>) <spanclass="hljs-comment"># Datetime from str, according to format.</span>
615
618
<D/DTn> = D/DT.fromordinal(<int>) <spanclass="hljs-comment"># D/DTn from days since Christ.</span>
616
-
<DTa> = DT.fromtimestamp(<real>, <tz>)<spanclass="hljs-comment"># DTa from seconds since Epoch in tz time.</span>
619
+
<DTa> = DT.fromtimestamp(<real>, <tz.>) <spanclass="hljs-comment"># DTa from seconds since Epoch in tz time.</span>
617
620
</code></pre>
618
621
<ul>
619
622
<li><strong>ISO strings come in following forms: <codeclass="python hljs"><spanclass="hljs-string">'YYYY-MM-DD'</span></code>, <codeclass="python hljs"><spanclass="hljs-string">'HH:MM:SS.ffffff[±<offset>]'</span></code>, or both separated by <codeclass="python hljs"><spanclass="hljs-string">'T'</span></code>. Offset is formatted as: <codeclass="python hljs"><spanclass="hljs-string">'HH:MM'</span></code>.</strong></li>
<li><strong>For abbreviated weekday and month use <codeclass="python hljs"><spanclass="hljs-string">'%a'</span></code> and <codeclass="python hljs"><spanclass="hljs-string">'%b'</span></code>.</strong></li>
<pre><codeclass="python language-python hljs"><iter> = <Path>.iterdir() <spanclass="hljs-comment"># Iterator with filenames located at path.</span>
1219
+
<pre><codeclass="python language-python hljs"><iter> = <Path>.iterdir() <spanclass="hljs-comment"># Iterator of filenames located at path.</span>
1213
1220
<iter> = <Path>.glob(<spanclass="hljs-string">'<pattern>'</span>) <spanclass="hljs-comment"># Filenames matching the wildcard pattern.</span>
1214
1221
</code></pre>
1215
1222
<pre><codeclass="python language-python hljs"><str> = str(<Path>) <spanclass="hljs-comment"># Returns path as a string.</span>
0 commit comments