LoginSignup
0
0

More than 3 years have passed since last update.

日付と時刻を指定の書式で取得する

Posted at

前書き

データを扱う際やログを取得する際に日付と時刻が必要になる機会は多いのですが、datetimeから欲しい書式のテキストを取得するためのメモ。

環境

Windows10 18363.1139
Python 3.9.0
Visual Studio Code 1.5.0

参考

datetime — Basic date and time types

サンプルコード

sample.py
from datetime import datetime

timestamp = datetime.now().strftime('%Y年%m月%d日%H時%M分%S秒')
print(timestamp)

結果

2020年10月18日15時45分50秒

補足

サンプル以外の使えるディレクティブは参考先ページのstrftime() and strptime() Behaviorを参考にする。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0