def datetime_string(dt):
"""Converts a tz-aware datetime.datetime into a string in git format."""
return dt.strftime('%Y-%m-%d %H:%M:%S %z')
# Adapted from: https://docs.python.org/2/library/datetime.html#tzinfo-objects
python类html()的实例源码
def _to_timestamp(date):
try:
return (date - EPOCH).total_seconds()
except AttributeError:
# The following is the equivalent of total_seconds() in Python2.6.
# See also: https://docs.python.org/2/library/datetime.html
delta = date - EPOCH
return ((delta.microseconds + (delta.seconds + delta.days * 24 * 3600)
* 10**6) / 10**6)
def _to_timestamp(date):
try:
return (date - EPOCH).total_seconds()
except AttributeError:
# The following is the equivalent of total_seconds() in Python2.6.
# See also: https://docs.python.org/2/library/datetime.html
delta = date - EPOCH
return ((delta.microseconds + (delta.seconds + delta.days * 24 * 3600)
* 10**6) / 10**6)
def dst(self, dt):
#ISO8601 specifies offsets should be different if DST is required,
#instead of allowing for a DST to be specified
# https://docs.python.org/2/library/datetime.html#datetime.tzinfo.dst
return datetime.timedelta(0)
def datetime_string(dt):
"""Converts a tz-aware datetime.datetime into a string in git format."""
return dt.strftime('%Y-%m-%d %H:%M:%S %z')
# Adapted from: https://docs.python.org/2/library/datetime.html#tzinfo-objects
def _to_timestamp(date):
try:
return (date - EPOCH).total_seconds()
except AttributeError:
# The following is the equivalent of total_seconds() in Python2.6.
# See also: https://docs.python.org/2/library/datetime.html
delta = date - EPOCH
return ((delta.microseconds + (delta.seconds + delta.days * 24 * 3600)
* 10**6) / 10**6)
def dst(self, dt):
#ISO 8601 specifies offsets should be different if DST is required,
#instead of allowing for a DST to be specified
# https://docs.python.org/2/library/datetime.html#datetime.tzinfo.dst
return datetime.timedelta(0)