localtime = time.localtime()
timeString = time.strftime('%Y%m%d%H%M%S', localtime)
timezone = -(time.altzone if localtime.tm_isdst else time.timezone)
timeString += 'Z' if timezone == 0 else '+' if timezone > 0 else '-'
timeString += time.strftime("%H'%M'", time.gmtime(abs(timezone)))
Python: date, time formatting