#-*- 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)
执行效果如下图所示
本文出自 “服务器” 博客,请务必保留此出处http://zhangfang2012.blog.51cto.com/6380212/1591760
原文:http://zhangfang2012.blog.51cto.com/6380212/1591760