Skip to content
pkienzle edited this page Jun 9, 2011 · 1 revision

The following ought to create a UTC timestamp based on local time plus offset. This should not be so hard!

def timestamp():
    """
    Construct a utc offset timestamp containing the local time.
    """
    t = time.localtime()
    dt = (time.timezone,time.altzone)[t.tm_isdst]
    local = time.strftime('%Y-%m-%dT%H:%M:%S',t)
    sign = "+" if dt > 0 else "-"
    offset = "%02d:%02d"%(abs(dt)//3600,(abs(dt)%3600)//60)
    return local+sign+offset
Clone this wiki locally