Python:更正时间戳中的本地时间

2024-02-09

Using https://gist.github.com/jordan-brough/4007432 https://gist.github.com/jordan-brough/4007432我有一个在 Sublime 中工作的时间戳,但时间晚了 7 小时。我怎样才能解决这个问题?我需要设置时区吗?

import sublime, sublime_plugin
from datetime import datetime

class TimestampCommand(sublime_plugin.TextCommand):
 def run(self, edit):
   stamp = datetime.utcnow().strftime("%m/%d/%y %H:%M %p - ")
   for r in self.view.sel():
    if r.empty():
      self.view.insert (edit, r.a, stamp)
    else:
      self.view.replace(edit, r,   stamp)

尝试更换datetime.utcnow() with datetime.now()

UTC = 协调世界时,时间偏移为 0

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python:更正时间戳中的本地时间 的相关文章

随机推荐