python et les dates

différences entre deux dates

import datetime
now = datetime.datetime.now()
print now
dat =datetime.datetime.fromtimestamp(float('1237770003'))
print dat
diff = now - dat
print diff
print diff.days

pour enlever ou a jouter x heures ou n jours

import datetime
from datetime import timedelta
now = datetime.datetime.now()
print now
d = timedelta(microseconds=-1)
print now -d
d = timedelta(hours=5)
print now -d
d = timedelta(hours=-5)
print now -d
d = timedelta(days=5)
print now -d
d = timedelta(days=-5)
print now -d

mise en forme de la date

import datetime
import time
now = datetime.datetime.now()
print now.strftime("%Y/%m/%d %H:%M:%S")