# -*- coding:UTF-8 -*-

import datetime, time


now = datetime.datetime.now()


print "日期输出格式化 datetime => string"

print now.strftime('%Y-%m-%d %H:%M:%S')


t_str = '2015-04-07 19:11:21'


d = datetime.datetime.strptime(t_str, '%Y-%m-%d %H:%M:%S')

print "字符串输出格式化string => datetime"

print d



d1 = datetime.datetime.strptime('2015-03-05 17:41:20', '%Y-%m-%d %H:%M:%S')


d2 = datetime.datetime.strptime('2015-03-02 17:41:20', '%Y-%m-%d %H:%M:%S')


delta = d1 - d2

print "两个日期相差多少天"

print delta.days  



now = datetime.datetime.now()

delta = datetime.timedelta(days=3)

n_days = now + delta

print "今天的n天后的日期"

print n_days.strftime('%Y-%m-%d %H:%M:%S')