ソースコード #!/usr/bin/python # coding: UTF-8 # 現在の日付・時刻の取得と出力 | datetimeクラスの属性、today()、strftime()メソッドの使い方 import datetime # datetimeモジュールのインポート import locale # import文はどこに書いてもOK(可読性などの為、慣例でコードの始めの方) # today()メソッドで現在日付・時刻のdatetime型データの変数を取得 d = datetime.datetime.today() # ↑モジュール名.クラス名.メソッド名 print 'd == %s : %s\n' % (d, type(d)) # Microsecond(10^-6sec)まで取得 # datetime型の各属性へのアクセス # year, month, day print
![Python: 現在の日付・時刻の取得と出力 – datetimeクラスの属性、today()、strftime()メソッド](https://cdn-ak-scissors.b.st-hatena.com/image/square/22c5887a1a17699b25e52574c2389ed9bc94fbc6/height=288;version=1;width=512/https%3A%2F%2Fyukun.info%2Fwp-content%2Fthemes%2Fsimplicity2-child%2Fimages%2Fog-image.jpg)