Python: Datetime

By Xah Lee. Date: .
# python 3
import datetime

dt = datetime.datetime.now()

print(dt)
# 2022-01-11 20:59:16.211811

print(dt.strftime("%Y%m%dT%H%M%S"))
# 20220111T205916

print(dt.strftime("%Y-%m-%dT%H:%M:%S"))
# 2022-01-11T20:59:16

print(dt.strftime("%Y%m%d_%H%M%S"))
# 20220111_205916

Python

Regex

Text Processing

Web

Misc