如何在 python27 中以精确的 UTC 格式“2015-05-28T22:55:00:000Z”打印时间

How to print time in exact UTC format "2015-05-28T22:55:00:000Z" in python27

我需要查看上述格式的输出。我试过了:

  1. datetime.datetime.utcnow().isoformat()[:-4]

  2. datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S:%f')[:-4]

最后不包含Z

只需添加Z

datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S:%f')[:-4] + 'Z'