Error:

Get current time

from datetime import datetime
now = datetime.now().time()
now # datetime.time(17, 29, 55, 89562)

Get current date

from datetime import datetime
today = datetime.now().date()
today # datetime.date(2013, 11, 29)

Convert date to epoch seconds

import calendar
from datetime import datetime
date = datetime(2013, 11, 29, 11, 57)
timestamp = calendar.timegm(date.utctimetuple())

Convert epoch seconds to date

import time
timestamp = 1385775522
# UTC
utc = time.gmtime(timestamp) 
utc # time.struct_time(tm_year=2013, tm_mon=11, tm_mday=30, tm_hour=1, tm_min=39, tm_sec=37, tm_wday=5, tm_yday=334, tm_isdst=0)
# Local timezone
local = time.localtime(1385775577)
local # time.struct_time(tm_year=2013, tm_mon=11, tm_mday=29, tm_hour=17, tm_min=39, tm_sec=37, tm_wday=4, tm_yday=333, tm_isdst=0) 

Get timestamp

import time
ts = time.time() # 1385775787.826039

Add to date

from datetime import datetime
from datetime import timedelta

today = datetime.now().date()
nextweek = today + timedelta(days = 7)
nextweek # datetime.date(2013, 12, 6)

Substract from date

from datetime import datetime
from datetime import timedelta

today = datetime.now().date()
prevweek = today - timedelta(days = 7)
prevweek # datetime.date(2013, 11, 22)

Difference between two dates

from datetime import datetime
from datetime import timedelta

d1 = datetime(2013, 11, 29, 13, 00)
d2 = datetime(2013, 12, 31, 23, 57)
delta = d2 - d1
delta # datetime.timedelta(32, 39420)

Get week number for the date

from datetime import datetime

d = datetime(2013, 11, 29)
weeknum = d.isocalendar()[1] # 48

Get day number in a year for the date

from datetime import datetime
from datetime import date

d = datetime(2013, 11, 29).date()
yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1  # 333

Get day number in a week for the date

from datetime import datetime

d = datetime(2013, 11, 29)
weekday = d.isoweekday() # 5 for Friday

Parse date from the string

from datetime import datetime

d = datetime.strptime('Nov 29 2013 1:33PM', '%b %d %Y %I:%M%p')
d # datetime.datetime(2013, 11, 29, 13, 33)

Format date

from datetime import datetime

d = datetime.now()
s = d.strftime('%b %d %Y %I:%M%p') # 'Nov 29 2013 05:53PM'

Sleep for number of seconds

import time
time.sleep(5)

Sleep for less than a second

import time
time.sleep(0.1)