gpt4 book ai didi

Python 日期时间提供错误的时区

转载 作者:行者123 更新时间:2023-12-01 02:32:59 26 4
gpt4 key购买 nike

我有一个 SublimeText 3 插件,它为我提供新文档的时间戳。一切正常,但我得到了错误的时区。我是东部时间,但它为我提供了提前 6 小时的时间 (UTC)。

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)

最佳答案

尝试 stamp = datetime.now().strftime("%A %B %d, %Y | %H:%M:%S")

datetime.now() 提供您的本地时间。

关于Python 日期时间提供错误的时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46588964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com