LoginSignup
1
3

More than 5 years have passed since last update.

python > 日付の型からyyyymmddを取得する > parsed = time.strptime(mddt) / yyyymmdd = time.strftime("%Y%m%d", parsed)

Last updated at Posted at 2016-03-08
動作確認
Raspberry Pi2 + raspbian

http://qiita.com/7of9/items/b35747318a251247a249
の続き。

ファイルの日付からyyyymmdd形式の文字列を取得したい。

参考 http://ja.pymotw.com/2/time/
参考 http://docs.python.jp/2/library/time.html

import os.path
import time

filepath = "/home/pi/BYOP/send.txt"
mddt = time.ctime(os.path.getmtime(filepath))
print mddt
parsed = time.strptime(mddt)
yyyymmdd = time.strftime("%Y%m%d", parsed)
print yyyymmdd
結果
Mon Mar  7 07:18:45 2016
20160307
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3