#-*- coding: utf-8 -*- import time NowYear = time.localtime()[0] NowMonth = time.localtime()[1] LastMonth = NowMonth - 1 if NowMonth == 1: LastMonth = 12 NowYear = NowYear -1 result = "%s-%s-%d" % (NowYear, LastMonth, 1) TimeStamp=time.mktime(time.strptime(result,'%Y-%m-%d')) #日期转换为时间戳 LocalTime = time.localtime(TimeStamp)#将日期时间戳转换为localtime print time.strftime('%Y-%m-%d',LocalTime)
执行效果如下图所示