Python: Correcting the local time in a timestamp

喜欢而已 提交于 2019-12-24 01:18:59

问题


Using https://gist.github.com/jordan-brough/4007432 I got a timestamp to work in sublime but the time is off by 7 hours. How can I fix this? Do I need to set the timezone?

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)

回答1:


Try replacing the datetime.utcnow() with datetime.now()

UTC = Coordinated Universal Time which has 0 time offset



来源:https://stackoverflow.com/questions/17650129/python-correcting-the-local-time-in-a-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!