本文介绍了Python:更正时间戳中的本地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用https://gist.github.com/jordan-brough/4007432我有一个可以在 sublime 中工作的时间戳,但时间差了 7 个小时.我怎样才能解决这个问题?我需要设置时区吗?
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)
推荐答案
尝试将 datetime.utcnow()
替换为 datetime.now()
UTC = 时间偏移为 0 的协调世界时
UTC = Coordinated Universal Time which has 0 time offset
这篇关于Python:更正时间戳中的本地时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!