问题
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