1
我有一個SublimeText 3插件,它爲我提供了新文檔的時間戳。一切正常,但我得到錯誤的時區。我是東部時間,但它提供了6小時(UTC)的時間。提供錯誤時區的Python日期時間
import sublime, sublime_plugin
from datetime import datetime
class TimestampCommand(sublime_plugin.TextCommand):
def run(self, edit):
stamp = datetime.utcnow().strftime("%A %B %d, %Y | %H:%M:%S")
for r in self.view.sel():
if r.empty():
self.view.insert (edit, r.a, stamp)
else:
self.view.replace(edit, r, stamp)
你很明顯在這裏要求'UTC'時區:'datetime.utcnow()'。無論是使用'datetime.now()',還是需要爲'datetime.utcnow()'提供一個偏移量來說明你的時區。 – Abdou
謝謝。我以爲我讀'utcnow'不得不用,我需要提供偏移,但如果我可以刪除'utc'和使用'datetime.now',然後我會走這條路!謝謝! –