python> Get yyyymmdd from date type> parsed = time.strptime (mddt) / yyyymmdd = time.strftime ("% Y% m% d", parsed)

Operation check


Raspberry Pi2 + raspbian

http://qiita.com/7of9/items/b35747318a251247a249 Continued.

I want to get a string in yyyymmdd format from the date of the file.

Reference http://ja.pymotw.com/2/time/ Reference 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

result


Mon Mar  7 07:18:45 2016
20160307

Recommended Posts

python> Get yyyymmdd from date type> parsed = time.strptime (mddt) / yyyymmdd = time.strftime ("% Y% m% d", parsed)
python> datetime> Get the datetime (eg 20151130) format string> print today.strftime ("% Y% m% d") / print "{:% Y% m% d}" .format ( today)
Extract rows that meet the conditions from Excel containing date data (% Y /% m /% d)
python> datetime> From date string (ISO format: 2015-12-09 12:40:08) to datetime type
[Python3] Get date diff
Get date in Python
Get date with python