[Small story] Get timestamp with Python

Introduction

I'm sorry for the ultra-small story, but as a memo for myself regarding the notation procedure

code

#Get time stamp

from datetime import datetime
from pytz import timezone
utc_now = datetime.now(timezone('UTC'))
jst_now = utc_now.astimezone(timezone('Asia/Tokyo'))
ts = jst_now.strftime("%Y%m%d-%H%M%S")
print(ts)

Result example

20200106-182252

This time, I used this format for the purpose of creating a part of the unique file name, but if you rewrite the part of "% Y% m% d-% H% M% S", you can do various things. It can be applied to patterns.

Recommended Posts

[Small story] Get timestamp with Python
python small story collection
Get date with python
[Small story] Test image generation with Python / OpenCV
Get country code with python
Get Twitter timeline with python
Get Youtube data with python
Stumble story with Python array
Get thread ID with python
Get started with Python! ~ ② Grammar ~
Get stock price with Python
Get home directory with python
Get keyboard events with python
Get Alembic information with Python
[Small story] Synchronize with Python without multithreading (limited use)
Get started with Python! ~ ① Environment construction ~
Link to get started with python
[Small story] [Python] Replace strings in 2D arrays with numbers
Get reviews with python googlemap api
Get web screen capture with python
Get the weather with Python requests 2
[Python] Get economic data with DataReader
How to get started with Python
Get Qiita trends with Python scraping
Get started with Python in Blender
Get weather information with Python & scraping
Get additional data in LDAP with python
Get property information by scraping with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
[Python] Get the variable name with str
Get Started with TopCoder in Python (2020 Edition)
[Python] Get Python package information with PyPI API
To work with timestamp stations in Python
How Python beginners get started with Python with Progete
Let's get along with Python # 0 (Environment construction)
[Blender x Python] Let's get started with Blender Python !!
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
[Python] Get the files in a folder with Python
Get a ticket for a theme park with python
[Python3] A story stuck with time zone conversion
Get stock price data with Quandl API [Python]
I tried to get CloudWatch data with Python
Get git branch name and tag name with python
A story stuck with handling Python binary data