Ad
1: 2018-01-05 (金) 04:25:34 njf ソース バックアップ No.1 を復元して編集 現: 2018-01-05 (金) 13:30:38 njf ソース 編集
Line 1: Line 1:
-Pythonでの日付の処理はdatetimeを使います。現在時刻の取得にはnowメソッドを使います。+Pythonでの日付の処理は「datetime」を使います。現在時刻の取得には「now」メソッドを使います。
 from datetime import datetime  from datetime import datetime
 now = datetime.now()  now = datetime.now()
 +
 +書式付きで出力するには「strftime」を使います。
 +
 + from datetime import datetime
 + 
 + now = datetime.now()
 + print now.strftime("%Y/%m/%d %H:%M:%S")
 +
 +結果
 + 2018/01/05 13:21:37
 +
 +個別に各値を取得するには以下のように各プロパティにアクセスします。
 +
 + print now.year
 + 
 + print now.month
 + 
 + print now.day
 + 
 + print now.hour
 + 
 + print now.minute
 + 
 + print now.second
 +
 +結果
 +
 + 2018
 + 1
 + 5
 + 13
 + 21
 + 37


トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード印刷に適した表示   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom Powered by xpWiki
Counter: 1611, today: 1, yesterday: 0
MenuBar
広告

ログイン

ユーザー名:


パスワード:





パスワード紛失

Portuguese | English | German | Greek | Japanese | Korean | Russian | T-Chinese top
NJF