-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a few simple TILs to Python category even
though they where used in jq context.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# strftime | ||
|
||
I was working with `jq` when I was reading some documentation which referenced `strftime`, when _googling_ I found this Python resource, which helped me, eventhough I should propably have found one in JavaScript anyway, this one worked for me. | ||
|
||
`strftime` can convert a DateTime object to a string in a given format. | ||
|
||
```python | ||
from datetime import datetime | ||
|
||
now = datetime.now() # current date and time | ||
|
||
year = now.strftime("%Y") | ||
print("year:", year) | ||
|
||
month = now.strftime("%m") | ||
print("month:", month) | ||
|
||
day = now.strftime("%d") | ||
print("day:", day) | ||
|
||
time = now.strftime("%H:%M:%S") | ||
print("time:", time) | ||
|
||
date_time = now.strftime("%m/%d/%Y, %H:%M:%S") | ||
print("date and time:",date_time) | ||
``` | ||
|
||
## Resources and References | ||
|
||
- [strftime resource](https://www.programiz.com/python-programming/datetime/strftime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# strptime | ||
|
||
I actually used this for a reference for solving some challenges for `jq` and I was reading some documentation which referenced `strftime`, when _googling_ I found this Python resource, which helped me, eventhough I should propably have found one in JavaScript anyway, this one worked for me. | ||
|
||
`strptime` can convert a string in a given format to a DateTime object. | ||
|
||
```python | ||
from datetime import datetime | ||
|
||
date_string = "21 June, 2018" | ||
|
||
print("date_string =", date_string) | ||
print("type of date_string =", type(date_string)) | ||
|
||
date_object = datetime.strptime(date_string, "%d %B, %Y") | ||
|
||
print("date_object =", date_object) | ||
print("type of date_object =", type(date_object)) | ||
``` | ||
|
||
## Resources and References | ||
|
||
- [strptime resource]https://www.programiz.com/python-programming/datetime/strptime#google_vignette) |