pythonで現在の日時を取得する方法/datetime.nowメソッドの使い方

watch IT

datetime.nowdatetimeモジュールのメソッドです。現在の日時を取得することができます。

スポンサーリンク

datetime.nowメソッド

python datetime date1
まずあらかじめdatetime組み込みモジュールをimportしておき、
#python
import datetime
print(datetime.datetime.now())
datetimeのあとにもう一回datetimeをつけて、nowを求めます。datetime.datetimeだけだと「日時を求める」命令で、そこに具体的な対象である「今」をくっつけてる形です。
python datetime date3
実行結果です。
Python操作方法、関数・メソッドリファレンス
使用用途別にまとめたPythonリファレンスページです。 初期準備、基本概念 ダウンロード、インストール、起動 ShellとEditor、保存、実行 保存したPythonの起動 コメント、docstring、行またぎ コメント、...

コメント

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny