- ソース を表示
- Python/現在の日付と時刻の取得 へ行く。
| 1: 2018-01-05 (金) 04:25:34 njf |
現: 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 | ||
- Python/現在の日付と時刻の取得 のバックアップ一覧
- Python/現在の日付と時刻の取得 のバックアップ差分(No. All)
- 1: 2018-01-05 (金) 04:25:34 njf
- 現: 2018-01-05 (金) 13:30:38 njf
| ぺージ情報 | |
|---|---|
| ぺージ名 : | Python/現在の日付と時刻の取得 |
| ページ別名 : | 未設定 |
| ページ作成 : | njf |
| 閲覧可 | |
| グループ : | すべての訪問者 |
| ユーザー : | すべての訪問者 |
| 編集可 | |
| グループ : | すべての訪問者 |
| ユーザー : | すべての訪問者 |
Counter: 2025,
today: 1,
yesterday: 0

