【问题标题】:Python: Correcting the local time in a timestampPython:在时间戳中更正本地时间
【发布时间】:2013-07-15 08:47:40
【问题描述】:

使用 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)

【问题讨论】:

  • 预期的结果是什么,你得到了什么?

标签: python time sublimetext


【解决方案1】:

尝试将datetime.utcnow() 替换为datetime.now()

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

【讨论】:

    猜你喜欢
    • 2020-02-02
    • 2017-06-15
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    • 2011-02-06
    • 2014-12-30
    相关资源
    最近更新 更多