MCPcopy Create free account
hub / github.com/EasyIME/PIME / format_timestamp

Function format_timestamp

python/python3/tornado/httputil.py:852–872  ·  view source on GitHub ↗

Formats a timestamp in the format used by HTTP. The argument may be a numeric timestamp as returned by `time.time`, a time tuple as returned by `time.gmtime`, or a `datetime.datetime` object. >>> format_timestamp(1359312200) 'Sun, 27 Jan 2013 18:43:20 GMT'

(
    ts: Union[int, float, tuple, time.struct_time, datetime.datetime]
)

Source from the content-addressed store, hash-verified

850
851
852def format_timestamp(
853 ts: Union[int, float, tuple, time.struct_time, datetime.datetime]
854) -> str:
855 """Formats a timestamp in the format used by HTTP.
856
857 The argument may be a numeric timestamp as returned by `time.time`,
858 a time tuple as returned by `time.gmtime`, or a `datetime.datetime`
859 object.
860
861 >>> format_timestamp(1359312200)
862 'Sun, 27 Jan 2013 18:43:20 GMT'
863 """
864 if isinstance(ts, (int, float)):
865 time_num = ts
866 elif isinstance(ts, (tuple, time.struct_time)):
867 time_num = calendar.timegm(ts)
868 elif isinstance(ts, datetime.datetime):
869 time_num = calendar.timegm(ts.utctimetuple())
870 else:
871 raise TypeError("unknown timestamp type: %r" % ts)
872 return email.utils.formatdate(time_num, usegmt=True)
873
874
875RequestStartLine = collections.namedtuple(

Callers 3

checkMethod · 0.90

Calls

no outgoing calls

Tested by 3

checkMethod · 0.72