Data e hora atual (now), com Unix Timestamp e Timezone diferente (pytz)

This commit is contained in:
Luiz Otávio
2022-12-12 09:49:05 -03:00
parent 37e8cc94a4
commit aafddc6716

View File

@@ -12,10 +12,14 @@
# pip install pytz types-pytz
from datetime import datetime
data_str_data = '2022/04/20 07:49:23'
data_str_data = '20/04/2022'
data_str_fmt = '%d/%m/%Y'
# from pytz import timezone
# data = datetime(2022, 4, 20, 7, 49, 23)
data = datetime.strptime(data_str_data, data_str_fmt)
print(data)
data = datetime.now()
print(data.timestamp()) # Isso está na base de dados
print(datetime.fromtimestamp(1670849077))
# data_str_data = '2022/04/20 07:49:23'
# data_str_data = '20/04/2022'
# data_str_fmt = '%d/%m/%Y'
# data = datetime(2022, 4, 20, 7, 49, 23, tzinfo=timezone('Asia/Tokyo'))
# data = datetime.strptime(data_str_data, data_str_fmt)