1.python获取当前日期

①方法1
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
today=time.strftime('%Y-%m-%d',time.localtime(time.time()))
print today


②方法2
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
today=datetime.date.today()
print today

2.获取昨天的日期

   

①方法1
#!/usr/bin/python
#-*-- coding:utf-8 -*-
import time
yesterday=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60))
print yesterday


②方法2
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
today=datetime.date.today()
yesterday=today-datetime.timedelta(days=1)
print yesterday