Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
Last active January 15, 2020 06:38
Show Gist options
  • Save heiwa4126/88700d72d431048b5b863f7838632695 to your computer and use it in GitHub Desktop.
Save heiwa4126/88700d72d431048b5b863f7838632695 to your computer and use it in GitHub Desktop.
python3でタイムゾーン付き現在時刻。すぐ忘れるのでメモ
from datetime import timezone, datetime
print(datetime.now(timezone.utc))
# 「today() および utcnow() よりもこの関数を使う方が好ましいです」だそうです。
# [datetime --- 基本的な日付型および時間型 — Python 3.8.1 ドキュメント](https://docs.python.org/ja/3/library/datetime.html)
@heiwa4126
Copy link
Author

実行例

$ python3
Python 3.6.8 (default, Oct  7 2019, 12:59:55)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import timezone, datetime
>>> print(datetime.now(timezone.utc))
2019-11-19 03:03:08.136066+00:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment