Python datetime提供错误的timezon

2024-09-28 22:21:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个sublimitext3的插件,它为我提供了新文档的时间戳。一切正常,但我拨错时区了。我是东部时间,但它为我提供了提前6小时(UTC)的时间。在

import sublime, sublime_plugin
from datetime import datetime

class TimestampCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    stamp = datetime.utcnow().strftime("%A %B %d, %Y | %H:%M:%S")
    for r in self.view.sel():
      if r.empty():
        self.view.insert (edit, r.a, stamp)
      else:
        self.view.replace(edit, r,   stamp)

Tags: from文档importself插件viewdatetimestamp