1. 程式人生 > >python 獲取前一天日期以及字串的格式化

python 獲取前一天日期以及字串的格式化

__author__ = 'wanghuafeng'
from datetime import timedelta, datetime

yesterday = datetime.today() + timedelta(-1)

yesterday_format = yesterday.strftime('%Y_%m_%d')
print yesterday_format #2015_01_05

filepath = '/home/ferrero/cloudinn/data/%s/prebuilds/'%yesterday_format
filepath2 = yesterday.strftime(r'/home/ferrero/cloudinn/data/%Y_%m_%d/prebuilds/')
print filepath#/home/ferrero/cloudinn/data/2015_01_05/prebuilds/
print filepath2#/home/ferrero/cloudinn/data/2015_01_05/prebuilds/