def art8601_format(dt):
"""
Format datetime object in ISO 8601 format suitable for Artifactory.
Artifactory's ISO 8601 timestamp parser is strict. It only accepts
3 sigificant digits of sub-second precision (milliseconds) instead
of the 6 significant digits (microseconds) in datetime.isoformat()
output.
I've raised a support ticket asking JFrog to consider relaxing
their parser.
Code adapted from standard python library.
"""
s = '%04d-%02d-%02dT%02d:%02d:%02d.%03d' % (
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second,
dt.microsecond / 1000)
utc_offset = dt.utcoffset()
if utc_offset is not None:
if utc_offset.days < 0:
sign = '-'
utc_offset = - utc_offset
else:
sign = '+'
hh, mm = divmod(utc_offset.seconds, 3600)
mm //= 60
s += "%s%02d%02d" % (sign, hh, mm)
else:
s += "Z"
return s
评论列表
文章目录